ADR-0042: Selection by state and --defer¶
Architecture: Section 7, Error codes, and section 11, Artifacts
Context¶
A developer who changes one model wants to build that model and what depends on it, and to read the parents they did not touch from production instead of rebuilding them in their own schema. dbt does this with --state, state:modified, result: and --defer. pipeloom has the pieces: compile --stable writes a manifest with a checksum for every node and the relation each persisted model is written to, and every run writes run_results.json. It has no way to compare against them or to read from them.
Options¶
- How
state:modifieddecides a node changed. - Compare the node
checksumof the reference with this project's. The checksum covers the canonical model config and the body bytes. It already leaves out the relation, which is computed separately from the naming strategy, so adevproject and aprodreference compare equal when nothing changed. Changing the checksum to drop target values is not needed. - The checksum misses rewired inputs, because they live in
PlanNode.inputs. The comparison key is therefore the checksum plus the sorted alias to unique id pairs. - How
--deferpoints a read at the reference. - Rewrite the relations of the plan before it runs. This changes
plan_hashand the manifest, so a deferred run and a plain run of the same project would no longer share a plan. Rejected. - Swap the read spec when the runner resolves a read. The plan, its hash and the manifest stay the same. Chosen.
- Whether
--deferchecks that the reference relation exists. - Check each one first. It costs a catalog round trip per parent and cannot know what this target may read.
- Trust the reference, as dbt does with
--favor-state, and let a missing table fail as PLM204 with a hint that names the reference relation. Chosen.
Decision¶
--state DIRonrun,compile,lsandgraph.DIR/manifest.jsonis required andDIR/run_results.jsonis optional; the artifacts root (target) works as is, because finalize copies both there. A relativeDIRis relative to the project dir.artifacts/reference.pyloads the reference. A missing folder, an unreadable manifest, a manifest of another project (the target may differ), or run results that are unreadable, have another schema or belong to another project are PLX110 (exit 1).state:modifiedselects a node that is absent from the reference or whose key differs, plus the persisted models that inline a modified ephemeral model.state:newselects a node absent from the reference. Other values are PLG305.+operators work as for any method.result:fail|skip|cancelled|succeededmatches the status of the model's row in the reference run results:failis failed or timed out,skipis skipped for any reason. Ephemeral models never match, as withunit:.- A
state:orresult:atom without--stateis PLG307, and aresult:atom when the folder has no run results is PLG308. Both are usage errors (exit 2). run --deferneeds--state(a click usage error without it). Every persisted model that the run does not build is read fromreference.nodes[uid].relation. Sources are never deferred, and ephemeral parents are inlined as always.- An intermediate parent, a parent missing from the reference, or one with no relation there is read from this target, and PLX112 warns. It counts under
--warn-error. - PLX111 (exit 2) refuses
--deferfor a unit invocation, for an effectiveboundary: task, and when the reference catalog kind differs from this target's or is missing.--manifestruns may defer. - The run results record
args.stateandargs.defer.model.input_readgainsrelationanddeferred, both additive.
Consequences¶
- Variables and environment values interpolated into a model's config sit inside its checksum, so changing one marks the node modified. A source change is not detected, because a source has no checksum. A Python model's checksum covers its module file, not the modules it imports.
- A manifest records the catalog kind only. With a filesystem catalog, the reference's
rootmust be the same as this target's for deferred reads to find the tables. - Task-boundary defer is refused in 0.8: each unit would run in a child process that does not know the reference. Use
--boundary process. state:modifiedon a project with no changes matches nothing, so PLG303 warns, and a run with--warn-errorfails.- Defer trusts the reference. A parent that was never built there, or that this target cannot read, fails the child with PLM204 and a hint that says so.
Status¶
Accepted. Amended in 0.9 by ADR-0050.
Amendment 0.9 (ADR-0050)¶
With Python-first authoring (ADR-0050) the checksum formula keeps its shape: the resolved config, the callable, a NUL byte and the bytes of the model's module file, plus columns without their description. The resolved config now includes what properties files and the models: tree of pipeloom.yml set, so a change in either marks the node modified. The body is always a module file, and editing any function in it marks every model of that file modified; this is conservative and accepted. Checksums and plan hashes change once for every project.