Unverified Commit bee95f0c authored by Marius van den Beek's avatar Marius van den Beek Committed by GitHub
Browse files

Merge pull request #14245 from mvdbeek/fix_nested_payload_validation

[22.05] Fix validation of nested element fetch data payloads
parents 1ae3d4c1 22f761aa
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ CompositeDataElement.update_forward_refs()


class NestedElement(BaseDataElement):
    items: List["AnyElement"] = Field(..., alias="elements")
    items: List[Union["AnyElement", "NestedElement"]] = Field(..., alias="elements")


AnyElement = Annotated[
+45 −0
Original line number Diff line number Diff line
@@ -81,6 +81,47 @@ recursive_archive_payload = {
}


nested_element_regression_payload = {
    "history_id": "80a1fcbe9fcb3c61",
    "targets": [
        {
            "destination": {"type": "hdca"},
            "elements": [
                {
                    "name": "a",
                    "elements": [
                        {
                            "name": "a",
                            "elements": [
                                {
                                    "url": "https://example.com",
                                    "src": "url",
                                    "dbkey": "?",
                                    "ext": "auto",
                                    "name": "forward",
                                },
                                {
                                    "url": "https://example.com",
                                    "src": "url",
                                    "dbkey": "?",
                                    "ext": "auto",
                                    "name": "reverse",
                                },
                            ],
                            "collection_type": "paired",
                        },
                    ],
                    "collection_type": "list:paired",
                },
            ],
            "collection_type": "list:list:paired",
            "name": "a",
        }
    ],
    "auto_decompress": True,
}


def test_fetch_data_schema():
    payload = FetchDataPayload(**example_payload)
    elements = payload.targets[0].items  # type: ignore[union-attr]  # alias doesn't type check properly
@@ -113,3 +154,7 @@ def test_recursive_archive_form_like_data():
    payload = deepcopy(recursive_archive_payload)
    payload["targets"] = dumps(payload["targets"])
    FetchDataPayload(**payload)


def test_nested_elemet_regression():
    FetchDataPayload(**nested_element_regression_payload)