Skip to content

Commit b49aa6e

Browse files
authored
Remove invalid validation of default included_resources (#956)
1 parent 74d2ff8 commit b49aa6e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
Note that in line with [Django REST Framework policy](http://www.django-rest-framework.org/topics/release-notes/),
99
any parts of the framework not mentioned in the documentation should generally be considered private API, and may be subject to change.
1010

11-
## Unreleased
11+
## [Unreleased]
1212

1313
### Fixed
1414

1515
* Include `PreloadIncludesMixin` in `ReadOnlyModelViewSet` to enable the usage of [performance utilities](https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#performance-improvements) on read only views (regression since 2.8.0)
16+
* Remove invalid validation of default `included_resources` (regression since 4.2.0)
1617

1718
## [4.2.0] - 2021-05-12
1819

example/serializers.py

+3
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ class Meta:
321321
# fields = ('entry', 'body', 'author',)
322322
meta_fields = ("modified_days_ago",)
323323

324+
class JSONAPIMeta:
325+
included_resources = ("writer",)
326+
324327
def get_modified_days_ago(self, obj):
325328
return (datetime.now() - obj.modified_at).days
326329

example/tests/test_serializers.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,25 @@ def test_model_serializer_with_implicit_fields(self, comment, client):
198198
"meta": {
199199
"modifiedDaysAgo": (datetime.now() - comment.modified_at).days
200200
},
201-
}
201+
},
202+
"included": [
203+
{
204+
"attributes": {
205+
"email": comment.author.email,
206+
"name": comment.author.name,
207+
},
208+
"id": str(comment.author.pk),
209+
"relationships": {
210+
"bio": {
211+
"data": {
212+
"id": str(comment.author.bio.pk),
213+
"type": "authorBios",
214+
}
215+
}
216+
},
217+
"type": "writers",
218+
}
219+
],
202220
}
203221

204222
response = client.get(reverse("comment-detail", kwargs={"pk": comment.pk}))

rest_framework_json_api/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def validate_path(serializer_class, field_path, path):
137137
validate_path(this_included_serializer, new_included_field_path, path)
138138

139139
if request and view:
140-
included_resources = get_included_resources(request, self)
140+
included_resources = get_included_resources(request)
141141
for included_field_name in included_resources:
142142
included_field_path = included_field_name.split(".")
143143
if "related_field" in view.kwargs:

0 commit comments

Comments
 (0)