From c6340ff1a666e61fd0b01c02e6b849467d51325e Mon Sep 17 00:00:00 2001 From: stibrew Date: Thu, 11 Jun 2026 13:15:56 +0200 Subject: [PATCH 1/2] fix: copy attributes passed from the user to avoid mutation --- src/zarr/core/group.py | 2 +- src/zarr/core/metadata/common.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index 44eefb3786..52eaa3e144 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -105,7 +105,7 @@ def parse_attributes(data: Any) -> dict[str, Any]: if data is None: return {} elif isinstance(data, dict) and all(isinstance(k, str) for k in data): - return data + return dict(data) msg = f"Expected dict with string keys. Got {type(data)} instead." raise TypeError(msg) diff --git a/src/zarr/core/metadata/common.py b/src/zarr/core/metadata/common.py index 44d3eb292b..6367bdb28a 100644 --- a/src/zarr/core/metadata/common.py +++ b/src/zarr/core/metadata/common.py @@ -10,4 +10,4 @@ def parse_attributes(data: dict[str, JSON] | None) -> dict[str, JSON]: if data is None: return {} - return data + return dict(data) From 4b719a9dfa57624094ab2a666af55e11bad08f69 Mon Sep 17 00:00:00 2001 From: stibrew Date: Thu, 11 Jun 2026 13:15:56 +0200 Subject: [PATCH 2/2] fix: copy attributes passed from the user to avoid mutation --- changes/4059.bugfix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/4059.bugfix.md diff --git a/changes/4059.bugfix.md b/changes/4059.bugfix.md new file mode 100644 index 0000000000..16fb582f65 --- /dev/null +++ b/changes/4059.bugfix.md @@ -0,0 +1 @@ +Prevents mutation of the attributes dict provided by the user by copying them instead of keeping the reference