diff --git a/python/CHANGELOG.rst b/python/CHANGELOG.rst index 7f4027dbf8..18907ba2e5 100644 --- a/python/CHANGELOG.rst +++ b/python/CHANGELOG.rst @@ -1,3 +1,12 @@ +-------------------- +[0.6.2] - 2025-XX-XX +-------------------- + +**Bugfixes** + +- Meatdata.schema was returning a modified schema, this is fixed to return a copy of + the original schema instead (:user:`benjeffery`, :issue:`3129`, :pr:`3130`) + -------------------- [0.6.1] - 2025-03-31 -------------------- diff --git a/python/tests/test_metadata.py b/python/tests/test_metadata.py index 632604deba..ce999e3fc3 100644 --- a/python/tests/test_metadata.py +++ b/python/tests/test_metadata.py @@ -1125,6 +1125,25 @@ def test_defaults_object_or_null(self): assert ms.validate_and_encode_row(None) == b"" assert ms.decode_row(b"") is None + def test_add_property_to_schema(self): + schema = metadata.MetadataSchema( + { + "codec": "struct", + "type": ["object", "null"], + "name": "Mutation metadata", + "properties": { + "s": {"type": "number", "binaryFormat": "d"}, + }, + "additionalProperties": False, + } + ) + schema_with_additional = schema.schema + schema_with_additional["properties"]["a"] = { + "type": "number", + "binaryFormat": "d", + } + metadata.MetadataSchema(schema_with_additional) + class TestStructCodecRoundTrip: def round_trip(self, schema, row_data): diff --git a/python/tskit/_version.py b/python/tskit/_version.py index 4d546301e4..10ab1b2014 100644 --- a/python/tskit/_version.py +++ b/python/tskit/_version.py @@ -1,4 +1,4 @@ # Definitive location for the version number. # During development, should be x.y.z.devN # For beta should be x.y.zbN -tskit_version = "0.6.1" +tskit_version = "0.6.2.dev0" diff --git a/python/tskit/metadata.py b/python/tskit/metadata.py index 7c217b553e..d40c3df262 100644 --- a/python/tskit/metadata.py +++ b/python/tskit/metadata.py @@ -778,6 +778,7 @@ class MetadataSchema: def __init__(self, schema: Mapping[str, Any] | None) -> None: self._schema = schema + self._unmodified_schema = schema self._bypass_validation = False if schema is None: @@ -835,7 +836,7 @@ def __eq__(self, other) -> bool: @property def schema(self) -> Mapping[str, Any] | None: # Return a copy to avoid unintentional mutation - return copy.deepcopy(self._schema) + return copy.deepcopy(self._unmodified_schema) def asdict(self) -> Mapping[str, Any] | None: """