Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d1163ce

Browse files
authored
Ensured that no fields are returned when sparse fields is set to an empty value (#1240)
1 parent 53469f3 commit d1163ce

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ any parts of the framework not mentioned in the documentation should generally b
1313
### Fixed
1414

1515
* Re-enabled overwriting of url field (regression since 7.0.0)
16+
* Ensured that no fields are rendered when sparse fields is set to an empty value. (regression since 7.0.0)
1617

1718
## [7.0.1] - 2024年06月06日
1819

‎rest_framework_json_api/renderers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def _filter_sparse_fields(cls, serializer, fields, resource_name):
439439
sparse_fieldset_value = request.query_params.get(
440440
sparse_fieldset_query_param
441441
)
442-
if sparse_fieldset_value:
442+
if sparse_fieldset_valueisnotNone:
443443
sparse_fields = sparse_fieldset_value.split(",")
444444
return {
445445
field_name: field

‎rest_framework_json_api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _readable_fields(self):
8989
sparse_fieldset_value = request.query_params.get(
9090
sparse_fieldset_query_param
9191
)
92-
if sparse_fieldset_value:
92+
if sparse_fieldset_valueisnotNone:
9393
sparse_fields = sparse_fieldset_value.split(",")
9494
return (
9595
field

‎tests/test_views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ def test_list_allow_overwiritng_url_with_sparse_fields(self, client, url_instanc
219219
}
220220
]
221221

222+
@pytest.mark.urls(__name__)
223+
def test_list_with_sparse_fields_empty_value(self, client, model):
224+
url = reverse("basic-model-list")
225+
response = client.get(url, data={"fields[BasicModel]": ""})
226+
assert response.status_code == status.HTTP_200_OK
227+
data = response.json()["data"]
228+
assert data == [
229+
{
230+
"type": "BasicModel",
231+
"id": str(model.pk),
232+
}
233+
]
234+
222235
@pytest.mark.urls(__name__)
223236
def test_retrieve(self, client, model):
224237
url = reverse("basic-model-detail", kwargs={"pk": model.pk})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /