in reviewhumanPR #50Data Facts
datafacts: first-class typed parents field on DatasetMetadata (follow-up to #35)
Follow-up #1 to #35 (closed as a duplicate of #31), the typed-lineage-field piece @dhve flagged as a clean, independent improvement.
Author
@Ngoga-Musagi
github profile →- Status
- In review
- Opened on
- Jul 1
- Branch
- hackathon/Ngoga-Musagi-datafacts-parents-field
Description
The pitch.
Follow-up #1 to #35 (closed as a duplicate of #31), the typed-lineage-field piece @dhve flagged as a clean, independent improvement.
## What
Adds a first-class, statically typed provenance field to `DatasetMetadata`:
```python
parents: list[DataFactsUrl] = Field(default_factory=lambda: list[DataFactsUrl]())
```
…and updates the merged `cid_facts` plugin (#31) to read it, keeping the old dict spelling working:
```python
def parents_of(dataset: DatasetMetadata) -> list[DataFactsUrl]:
if dataset.parents: # typed field wins
return list(dataset.parents)
raw = dataset.metadata.get("parents", []) # legacy fallback, backward compatible
...
```
## Why
#31 declares lineage via `metadata["parents"]` — a free-form, untyped, undiscoverable dict entry. A typed field is statically checkable, IDE-discoverable, and self-documenting. Both @Hiten0305l and I independently proposed it on our closed PRs, which @dhve noted is a strong signal it's the right design.
## Non-breaking by construction
- `content_hash()` is **untouched**. Because `publish()` still folds parents into the content hash via `metadata`, a dataset declared through the typed field and one declared through the dict **content-address to the identical URL** — verified by a new test.
- #31's entire 44-test `cid_facts` suite passes unchanged.
## Tests
`packages/nest-plugins-reference/tests/test_cid_facts_parents_field.py` (6 tests): default empty, typed field read, legacy dict still works, address parity between the two spellings, typed-takes-precedence, and phantom-parent rejection via the typed field.
## Verify
```
uv run ruff check . && uv run ruff format --check . && uv run pyright && uv run pytest -q
# 740 passed, 1 skipped
```
## Coordination
@dhve — on #39 you asked @Hiten0305l and me to coordinate on this so it isn't submitted twice. You listed it as item #1 on my #35, and it originated in my closed PR, so I'm carrying it here. Happy to adjust if you'd prefer otherwise.
Try it
Open PR on GitHubView diffCheckout locally
git fetch origin pull/50/head:pr-50
git checkout pr-50