Skip to content
Open
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
35 changes: 35 additions & 0 deletions src-python/tests/test_trp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,41 @@ def test_tbbox_union():
assert (b_union == b_gt)


def test_geometry_schema_ignores_unknown_fields():
"""
Ensure unknown fields are excluded during load for Geometry schema.
This validates BaseSchema Meta.unknown = EXCLUDE across nested schemas.
"""
geometry_input = {
"BoundingBox": {
"Width": 1.0,
"Height": 1.0,
"Left": 0.0,
"Top": 0.0,
# Unknown field inside nested schema
"BogusField": "should be ignored",
},
"Polygon": [
{"X": 0.0, "Y": 0.0},
{"X": 1.0, "Y": 0.0},
{"X": 1.0, "Y": 1.0},
{"X": 0.0, "Y": 1.0},
],
# Unknown field at top-level geometry
"Foo": "bar",
"AnotherUnknown": {"nested": 1},
}

geom = t2.TGeometrySchema().load(geometry_input) # type: ignore
assert isinstance(geom, t2.TGeometry)

dumped = t2.TGeometrySchema().dump(geom)
# Unknown fields should not appear in dump
assert "Foo" not in dumped
assert "AnotherUnknown" not in dumped
assert "BogusField" not in dumped.get("BoundingBox", {})


def test_get_blocks_for_relationship(caplog):
caplog.set_level(logging.DEBUG)

Expand Down
16 changes: 4 additions & 12 deletions src-python/trp/trp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class BaseSchema(m.Schema):
"""
SKIP_VALUES = set([None])

class Meta:
# Exclude unknown fields during load to be lenient with inputs
unknown = m.EXCLUDE

@m.post_dump
def remove_skip_values(self, data, many, pass_many=False):
return {
Expand Down Expand Up @@ -839,10 +843,6 @@ def link_tables(self, table_array_ids: List[List[str]]):


class THttpHeadersSchema(BaseSchema):

class Meta:
unknown = m.EXCLUDE

date = m.fields.String(data_key="date", required=False)
x_amzn_request_id = m.fields.String(data_key="x-amzn-requestid", required=False, allow_none=False)
content_type = m.fields.String(data_key="content-type", required=False, allow_none=False)
Expand All @@ -855,10 +855,6 @@ def make_thttp_headers(self, data, **kwargs):


class TResponseMetadataSchema(BaseSchema):

class Meta:
unknown = m.EXCLUDE

request_id = m.fields.String(data_key="RequestId", required=False, allow_none=False)
http_status_code = m.fields.Int(data_key="HTTPStatusCode", required=False, allow_none=False)
retry_attempts = m.fields.Int(data_key="RetryAttempts", required=False, allow_none=False)
Expand All @@ -870,10 +866,6 @@ def make_tresponse_metadata(self, data, **kwargs):


class TDocumentSchema(BaseSchema):

class Meta:
unknown = m.EXCLUDE

document_metadata = m.fields.Nested(TDocumentMetadataSchema,
data_key="DocumentMetadata",
required=False,
Expand Down