Skip to content

Fix tracking_id is minted per CMORiser, not per file - #690

Merged
rhaegar325 merged 1 commit into
mainfrom
fix_tracking_id_issue
Sep 3, 2026
Merged

Fix tracking_id is minted per CMORiser, not per file#690
rhaegar325 merged 1 commit into
mainfrom
fix_tracking_id_issue

Conversation

@rhaegar325

Copy link
Copy Markdown
Collaborator

#Solve 689

Fix

Branch fix_tracking_id_issue. base.py, +28 lines: _write_single takes its global attributes from a new helper instead of reading self.ds.attrs directly.

def _file_global_attributes(self) -> Dict[str, Any]:
    attrs = dict(self.ds.attrs)
    existing = attrs.get("tracking_id")
    if isinstance(existing, str) and "/" in existing:
        prefix = existing.rsplit("/", 1)[0]
        attrs["tracking_id"] = f"{prefix}/{uuid.uuid4()}"
    return attrs

Three choices worth recording:

  • The prefix is carried over from the existing id, not repeated here, so the CMIP6 (hdl:21.14100) and CMIP7 (hdl:21.14107) handles stay defined in their vocabularies. A dataset with no usable id is left alone.
  • A copy is returned. The dataset is reused across split writes, so mutating self.ds.attrs would leak into later files. The returned dict is only ever read downstream (membership check, generate_filename, _build_drs_path, and the write loop), so reference-to-copy changes nothing else.
  • creation_date is deliberately not refreshed. Files written in one run legitimately share a creation time, and nothing requires it to differ per file.

Validation

Unit teststests/unit/test_tracking_id_per_file.py, 8 tests. Seven cover the helper (distinct ids, prefix preserved, dataset not mutated, other attributes carried through, unusable id left alone); TestSplitWriteMintsIdPerFile drives write() end to end and reads the ids back off disk.

That last one matters: covering only the helper leaves the call site untested — _write_single could revert to self.ds.attrs and the other seven would still pass. Mutation-checked in both directions:

Mutation Result
call site reverted to self.ds.attrs 1 failed (the end-to-end test)
helper stops minting a new id 3 failed

Full suite: 2108 passed.

Real data — years 101–103 with split_years=1, so one CMORiser writes three files, which is the shape the defect needs:

PASS CMIP7 day tas   : 3 files / 3 unique ids, prefix ok
PASS CMIP6 Omon.tos  : 3 files / 3 unique ids, prefix ok

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.7%. Comparing base (166e8ca) to head (893c187).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #690   +/-   ##
=====================================
  Coverage   78.6%   78.7%           
=====================================
  Files         41      41           
  Lines       9021    9028    +7     
  Branches    1687    1688    +1     
=====================================
+ Hits        7094    7101    +7     
  Misses      1592    1592           
  Partials     335     335           
Flag Coverage Δ
unit 78.7% <100.0%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rhaegar325
rhaegar325 merged commit a6e2bd4 into main Sep 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant