Skip to content

Commit cd7c89f

Browse files
docs: fix partition_pattern order preservation
The partition_pattern was not preserving the order of attributes specified in the pattern because it was iterating over a set (unordered). This caused paths like 'neuron_id=0/mouse_id=5/session_date=2017-01-05/...' instead of the expected 'mouse_id=5/session_date=2017-01-05/neuron_id=0/...'. Changes: - Extract partition attributes as a list to preserve order - Keep a set for efficient lookup when filtering remaining PK attributes - Iterate over the ordered list when building partition path components Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent c3e0163 commit cd7c89f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/datajoint/storage.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,19 @@ def build_object_path(
234234
# Build primary key path components
235235
pk_parts = []
236236
partition_attrs = set()
237+
partition_attr_list = []
237238

238239
# Extract partition attributes if pattern specified
239240
if partition_pattern:
240241
import re
241242

242-
partition_attrs = set(re.findall(r"\{(\w+)\}", partition_pattern))
243+
# Preserve order from pattern
244+
partition_attr_list = re.findall(r"\{(\w+)\}", partition_pattern)
245+
partition_attrs = set(partition_attr_list) # For fast lookup
243246

244-
# Build partition prefix (attributes specified in partition pattern)
247+
# Build partition prefix (attributes in order from partition pattern)
245248
partition_parts = []
246-
for attr in partition_attrs:
249+
for attr in partition_attr_list:
247250
if attr in primary_key:
248251
partition_parts.append(f"{attr}={encode_pk_value(primary_key[attr])}")
249252

0 commit comments

Comments
 (0)