fix: resolve forward refs between YAML-only snapshots - #84
Merged
Conversation
`process_yaml_snapshot_nodes` registered nodes and resolved edges in a single pass, so a snapshot whose `relation: ref(...)` pointed to another YAML-only snapshot declared later in the file would fail to find it in `node_map`. `resolve_ref` would fall through to the `model.<name>` default and create an incorrect phantom node instead. Split the function into two passes: first register all YAML-only snapshot nodes, then resolve their upstream edges. SQL-registered snapshots are excluded from both passes (their edges are handled by `process_sql_edges`). Add a regression test covering the forward-declaration case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion Pass 1 used `sql_registered` to skip SQL-registered snapshot nodes but did not guard against duplicate YAML definitions sharing the same name. Two definitions with identical names would create two graph nodes with the same `unique_id`; `node_map` would be overwritten to the last one, leaving the first as an orphan. Replace the `sql_registered` set with a `yaml_registered` set that records which unique_ids were actually added by Pass 1. Pass 1 now checks `gb.node_map.contains_key` to skip both SQL-registered nodes (present before the pass) and YAML duplicates (inserted earlier in the same pass). Pass 2 iterates only over `yaml_registered`, which cleanly excludes both categories. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes order-dependent lineage resolution for dbt v1.9+ YAML-only snapshots by ensuring forward ref()s between snapshots declared in the same YAML file resolve to snapshot.<name> nodes (instead of incorrectly creating phantom model.<name> nodes).
Changes:
- Refactored YAML-only snapshot processing into a two-pass flow: register all snapshot nodes first, then resolve
relation:edges. - Added a regression test covering forward-declared YAML-only snapshot
ref()dependencies.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/dlin-core/src/graph/builder/mod.rs | Splits YAML-only snapshot handling into node-registration and edge-resolution passes to remove order dependence. |
| crates/dlin-core/src/graph/builder/tests/build_graph.rs | Adds a test ensuring forward ref()s between YAML-only snapshots don’t create phantom nodes and produce the correct edge. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
`yaml_registered.contains()` matched every definition sharing a name, so duplicate YAML snapshot entries could all add edges to the single registered node in pass 2 — producing duplicate or conflicting edges. Switch to `yaml_registered.remove()` so only the first definition seen (which matches the one registered in pass 1) contributes edges. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
process_yaml_snapshot_nodesregistered nodes and resolved edges in a single pass, causing order-dependent lineage for YAML-only snapshotsrelation: ref(other_snapshot)whereother_snapshotis declared later in the same file would incorrectly create a phantommodel.<name>node instead of linking tosnapshot.<name>Test plan
test_build_graph_yaml_only_snapshot_ref_forward_declarationcovering the forward-declaration case (no phantom node created, correct snapshot-to-snapshot edge)cargo fmtandcargo clippyclean🤖 Generated with Claude Code