RF: Derive LocalZarrEntry.filepath from zarr_basepath and parts#1843
RF: Derive LocalZarrEntry.filepath from zarr_basepath and parts#1843yarikoptic merged 1 commit intomasterfrom
Conversation
Previously LocalZarrEntry stored both filepath and (zarr_basepath, parts), two representations of the same fact kept in sync only by convention inside _get_subpath and parent. Convert filepath to a @Property derived as zarr_basepath.joinpath(*parts), removing the possibility of internal inconsistency. zarr_basepath is now the only on-disk state field; parts (inherited from BasePath) is the single source of truth for the entry's position within the zarr. The only direct construction site, ZarrAsset.filetree, drops the now unneeded filepath= argument.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1843 +/- ##
==========================================
- Coverage 76.30% 76.26% -0.05%
==========================================
Files 87 87
Lines 12484 12486 +2
==========================================
- Hits 9526 9522 -4
- Misses 2958 2964 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
sounds good to me, but I am still a little cautious -- do history digging on how having both came about -- I wonder if there could be a case not covered by tests which require them to diverge somehow? |
yarikoptic
left a comment
There was a problem hiding this comment.
please provide historical context on how two came about
|
@yarikoptic — historical context as requested:
So the invariant |
Summary
LocalZarrEntrypreviously stored bothfilepathand(zarr_basepath, parts)— two representations of the entry's position within the zarr, kept in sync only by convention inside_get_subpathandparent. This PR makesfilepatha@propertyderived aszarr_basepath.joinpath(*parts), so the two states can no longer disagree. Internally the only direct construction site,ZarrAsset.filetree, drops its now-redundantfilepath=argument.Compatibility
LocalZarrEntryis exported indandi.files, so external code could in principle depend onfilepathbeing a dataclass field. A GitHub code search suggests this is unlikely in practice:gh search code 'LocalZarrEntry'returns only one match outside this repo (tushkum34-cloud/pylibsmeta), and it is an auto-generated JSON snapshot of public-symbol metadata — not source code that uses the class.gh search code 'LocalZarrEntry('finds zero direct constructor calls outside this repo.entry.filepath) remain source-compatible with a property; only callers that passfilepath=to the constructor or usedataclasses.replace(entry, filepath=...)would be affected, and none were found.Private/unindexed code cannot be ruled out, but the realistic exposure surface is very small.
Verification
tox -e lint,typing— pass.hatch run test:run dandi/tests/test_files.py -k "zarr or Zarr"— 14 passed.Release Notes
Refactor
LocalZarrEntrysofilepathis derived fromzarr_basepathandpartsinstead of being stored separately, eliminating the possibility of internal inconsistency between the two representations.