Skip to content
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
10 changes: 10 additions & 0 deletions src/dso_api/dynamic_api/filters/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@ def _translate_raw_value( # noqa: C901
# or ?ligtInPanden=... references their identifier as foreign key.
return filter_input.raw_value

if field_schema.is_array_of_objects:
try:
items = field_schema["items"]
parser = SCALAR_PARSERS[items.get("format") or items["type"]]
except KeyError as e:
raise ValidationError(
f"Array of objects field '{filter_part.name}' "
f"should be filtered on with a .subfield"
) from e

if field_schema.is_array:
items = field_schema["items"]
parser = SCALAR_PARSERS[items.get("format") or items["type"]]
Expand Down
13 changes: 13 additions & 0 deletions src/tests/test_dynamic_api/views/test_api_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ def test_no_such_field(api_client, afval_dataset, filled_router):
reason = response.data["invalid-params"][0]["reason"]
assert reason == "Field 'nonexistent' does not exist"

@staticmethod
def test_array_of_objects_field(api_client, bag_dataset, filled_router):
"""Prove that not filtering on a subfield of an array of objects will crash."""
response = api_client.get("/v1/bag/verblijfsobjecten/?gebruiksdoel=test")
data = read_response_json(response)

assert response.status_code == HTTP_400_BAD_REQUEST, data
reason = data["invalid-params"][0]["reason"]
assert (
reason
== "Array of objects field 'gebruiksdoel' should be filtered on with a .subfield"
)

@staticmethod
@pytest.mark.parametrize(
"url",
Expand Down
Loading