Skip to content

Remove invalid validation of default included_resources #956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Note that in line with [Django REST Framework policy](http://www.django-rest-framework.org/topics/release-notes/),
any parts of the framework not mentioned in the documentation should generally be considered private API, and may be subject to change.

## Unreleased
## [Unreleased]

### Fixed

* 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)
* Remove invalid validation of default `included_resources` (regression since 4.2.0)

## [4.2.0] - 2021-05-12

Expand Down
3 changes: 3 additions & 0 deletions example/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ class Meta:
# fields = ('entry', 'body', 'author',)
meta_fields = ("modified_days_ago",)

class JSONAPIMeta:
included_resources = ("writer",)

def get_modified_days_ago(self, obj):
return (datetime.now() - obj.modified_at).days

Expand Down
20 changes: 19 additions & 1 deletion example/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,25 @@ def test_model_serializer_with_implicit_fields(self, comment, client):
"meta": {
"modifiedDaysAgo": (datetime.now() - comment.modified_at).days
},
}
},
"included": [
{
"attributes": {
"email": comment.author.email,
"name": comment.author.name,
},
"id": str(comment.author.pk),
"relationships": {
"bio": {
"data": {
"id": str(comment.author.bio.pk),
"type": "authorBios",
}
}
},
"type": "writers",
}
],
}

response = client.get(reverse("comment-detail", kwargs={"pk": comment.pk}))
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_json_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def validate_path(serializer_class, field_path, path):
validate_path(this_included_serializer, new_included_field_path, path)

if request and view:
included_resources = get_included_resources(request, self)
included_resources = get_included_resources(request)
for included_field_name in included_resources:
included_field_path = included_field_name.split(".")
if "related_field" in view.kwargs:
Expand Down