Skip to content

Return unmodified schema from MD.schema #3130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2025
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
9 changes: 9 additions & 0 deletions python/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
--------------------
Expand Down
19 changes: 19 additions & 0 deletions python/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/tskit/_version.py
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion python/tskit/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
"""
Expand Down
Loading