Skip to content

make() may add rows to entry tables when their origin is recorded; fan-out is one case - #325

Open
dimitri-yatsenko wants to merge 4 commits into
mainfrom
docs/make-writes-entry-tables
Open

dimitri-yatsenko wants to merge 4 commits into
mainfrom
docs/make-writes-entry-tables

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

A make() may add rows to entry tables (dj.Manual), not only to its own table and Parts, whenever a foreign key from those rows to the job would be wrong or impossible, provided the origin of each row is recorded. This PR generalizes the fan-out ingestion page to say that. Fan-out becomes one case among several.

What changes

  • New: explanation/writing-to-entry-tables.md (Writing to Entry Tables from make()):
    • what the dependency graph cannot record, and the two ways origin is recorded instead: the hidden _prov attribute and a modeled attribute;
    • when a foreign key is wrong or impossible: fan-out ingestion, iterative computations (with a new figure), closed-loop and adaptive experiments, a selected result becoming a parameter, and work queues for people;
    • the rules for such writes: same transaction, keys derived from the job key, add rows but never change them, insert values rather than a query, entry tables only;
    • what to do when the target row already exists: error, verify (written in user code), skip, or replace, with the effect of each on _prov.
  • New: how-to/write-entry-rows-from-make.md (Write Entry Rows from make()). It folds in the former explanation/fan-out-ingestion.md, which becomes a redirect, and adds:
    • the iterative recipe;
    • an insert1_or_verify helper;
    • how to clean up after deleting a job's rows;
    • how to find a job's rows through _prov.
  • Rule 4 of the make() contract in reference/specs/autopopulate.md is generalized, and explanation/computation-model.md and reference/specs/trace.md now match it.
  • reference/specs/boundary-provenance.md: the "Inside make()" section covers all such writes. It now says what skip_duplicates and replace do to _prov.
  • Supporting files:
    • scripts/gen_iterative_diagram.py generates images/iterative-entry-writes.svg;
    • examples/iterative_entry_writes.py is the runnable iterative example;
    • examples/fan_out_provenance.py is fixed: it now reads _prov with SQL (proj("_prov") raises), turns capture on, and calls drop(prompt=False).

insert(replace=True) currently fails on PostgreSQL (datajoint-python#1780). Both new pages carry a warning about it.

Checked

  • Every code sample ran on MySQL 8 and PostgreSQL 16 against datajoint-python master, with origin capture on:
    • the iterative loop;
    • the _prov context of a written row;
    • the verify helper (absent, equal, and different rows);
    • the clean-up recipe and the duplicate-error variant;
    • the four _prov string restrictions;
    • the fan-out example.
  • Each behavioral claim was checked against the library source.

Overlaps with #322 (tier names), which edits the same pages; whichever merges second rebases.

Generalize the fan-out ingestion page: a make() may write new rows into
entry tables whenever a foreign key from them to the job would be wrong
or impossible, as long as their origin is recorded (_prov plus a modelled
attribute). Fan-out is one case; iterative computations, adaptive
experiments, promoted parameters, and review queues are others.

- explanation/writing-to-entry-tables.md (new): when and why, the rules,
  and what to do when the target row already exists (error, verify,
  skip, replace), with the replace=True PostgreSQL caveat (#1780).
- how-to/write-entry-rows-from-make.md (new): fan-out ingestion (folded
  in from explanation/fan-out-ingestion.md, now a redirect), iterative
  computations, a verify helper, clean-up, finding rows by _prov.
- autopopulate spec rule 4, computation model, boundary-provenance spec,
  and cross-links updated.
- iterative figure (scripts/gen_iterative_diagram.py) and runnable
  example (examples/iterative_entry_writes.py).
- populate() raises on a duplicate; only reserve_jobs=True marks the job
- verify is written in user code; insert has no flag for it
- rows copied by inserting a query do not record the job
- trace spec and computation model no longer say writes go only to self
- boundary-provenance: replace caveats (dependents, PostgreSQL #1780)
- fan-out example: read _prov with SQL, turn capture on, drop(prompt=False)
- modeled spelling; see-also separators
MilagrosMarin
MilagrosMarin previously approved these changes Dec 1, 2026

@MilagrosMarin MilagrosMarin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dimitri-yatsenko, this is a clear generalization: fan-out now reads as one case of a rule instead of a one-off exception, and the explanation/how-to split fits well.

I checked the behavioral claims against datajoint-python master and ran both examples on MySQL 8 and PostgreSQL 16:

  • proj("_prov") raises; skip_duplicates=True keeps the stored values and _prov; replace=True writes a new _prov on MySQL and is refused with an FK error when a Computed row depends on the stored row; on PostgreSQL it fails with the REPLACE syntax error from datajoint/datajoint-python#1780.
  • Inserting from a query carries the source row's _prov and adds no context; the ingesting context is set around the whole make(), including make_insert.
  • examples/iterative_entry_writes.py and examples/fan_out_provenance.py run cleanly on both backends, and scripts/gen_iterative_diagram.py regenerates the SVG byte-for-byte.
  • mkdocs build --strict passes, the redirect from explanation/fan-out-ingestion/ lands on the new how-to, and no page still links the old path.

Two small things:

  • Rule 4 in reference/specs/autopopulate.md says "existing rows are never modified" and then lists replace as one of the choices. The explanation page's wording ("never change rows that results were computed from") is the accurate one, since replace is refused in exactly that case. Could rule 4 use the same phrasing?
  • #322 edits explanation/fan-out-ingestion.md, which this PR removes, so whichever lands second will need to carry the tier-name changes into how-to/write-entry-rows-from-make.md, not just resolve the conflict.

Nit: the fan-out snippet in the how-to declares file_id : uuid while the runnable example uses an integer key; matching them would avoid a double take.

With the rule 4 wording aligned, this is ready from my side.

…d from; integer file_id in the fan-out snippet
@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

Thanks @MilagrosMarin. 39321a2: rule 4 now says the make() never changes rows that results were computed from, matching the explanation page, and the how-to's fan-out snippet uses file_id : int32 like the runnable example. Noted on #322: whichever lands second carries the tier names into how-to/write-entry-rows-from-make.md.

This branch has not been deployed

No deployments
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.

2 participants