Skip to content

Commit 1e8efa1

Browse files
authored
Merge pull request #1109 from benjeffery/no_additional_properties
Raise error when additional_properties specified for struct codec
2 parents d67dfb4 + 22358e9 commit 1e8efa1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

python/tests/test_metadata.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,18 @@ def test_too_long_array(self):
14781478
):
14791479
metadata.MetadataSchema(schema).validate_and_encode_row(data2)
14801480

1481+
def test_additional_properties(self):
1482+
schema = {
1483+
"codec": "struct",
1484+
"type": "object",
1485+
"additional_properties": True,
1486+
"properties": {},
1487+
}
1488+
with pytest.raises(
1489+
ValueError, match="Struct codec does not support additional_properties"
1490+
):
1491+
metadata.MetadataSchema(schema)
1492+
14811493

14821494
class TestSLiMDecoding:
14831495
"""

python/tskit/metadata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ def enforce_fixed_properties(obj):
455455
elif type(obj) == dict:
456456
ret = {k: enforce_fixed_properties(v) for k, v in obj.items()}
457457
if ret.get("type") == "object":
458+
if ret.get("additional_properties"):
459+
raise ValueError(
460+
"Struct codec does not support additional_properties"
461+
)
458462
ret["required"] = list(ret.get("properties", {}).keys())
459463
ret["additionalProperties"] = False
460464
return ret

0 commit comments

Comments
 (0)