Commit 1223d88
authored
## Summary
Fixes [#33856](#33856) —
column lineage emitted by `.fetch_column_metadata()` referenced
default-derived `AssetKey`s instead of the translated keys actually
present in the asset graph when assets were defined via
`DBTProjectComponent`.
`_build_column_lineage_metadata()` resolved upstream dependencies by
calling `dagster_dbt_translator.get_asset_key(parent_resource_props)`.
But `DbtProjectComponentTranslator` (and any translator that customizes
translation via `get_asset_spec`) does **not** override `get_asset_key`
— it overrides `get_asset_spec`. As a result, every upstream
`TableColumnDep` pointed at a key that didn't exist in the graph, and
column lineage failed to resolve.
## Fix
Switch the upstream key resolution to
`dagster_dbt_translator.get_asset_spec(manifest, parent_unique_id,
project).key`. This is already the canonical pattern in the same file
(`_to_model_events` at `dbt_cli_event.py:401`) and in
`asset_utils.py:823`.
Chose this over an `isinstance(translator,
DbtProjectComponentTranslator)` branch because:
1. **Consistency** — matches how the materialized asset's own key is
resolved a few lines away. Using a different mechanism for upstream
resolution is what caused this drift bug in the first place.
2. **Generality** — works for any translator subclass that customizes
via `get_asset_spec` (the documented extension point), not just
`DbtProjectComponentTranslator`.
3. **No layering violation** — avoids importing a component-layer class
into core event code.
4. **Default path preserved** — `DagsterDbtTranslator.get_asset_spec()`
internally calls `self.get_asset_key()`, so users who only override
`get_asset_key` are unaffected.
To make this work, `project: DbtProject | None` is plumbed through
`_build_column_lineage_metadata` → `_get_lineage_metadata` →
`_get_materialization_metadata`. `_to_model_events` already had
`project` available, and `DbtCliInvocation.project` is the source at the
`_fetch_column_metadata` call site.
### Out of scope
`_to_observation_events_for_test` (`dbt_cli_event.py:498`) and
`freshness_builder.py` use the same `get_asset_key()` pattern and likely
have the same bug for `DbtProjectComponent` users. Kept this PR tight to
the reported column-lineage issue; those are follow-ups.
## Test plan
- [x] New regression test
`test_column_lineage_uses_get_asset_spec_for_upstream_keys` in
`test_columns_metadata.py` — uses a translator that overrides only
`get_asset_spec` (mimicking `DbtProjectComponentTranslator`'s pattern)
and asserts every upstream key in the emitted `TableColumnLineage`
carries the translated `renamed/...` prefix.
- [x] Verified the new test **fails** without the fix (`AssertionError:
Upstream key AssetKey(['raw_source_customers']) in column lineage was
not translated via get_asset_spec`) and passes with it.
- [x] All 12 duckdb-based column-lineage tests in
`test_columns_metadata.py` pass locally (snowflake/bigquery variants
skipped — require cloud credentials).
- [x] `make ruff` clean.
1 parent 3afb562 commit 1223d88
3 files changed
Lines changed: 91 additions & 3 deletions
File tree
- python_modules/libraries/dagster-dbt
- dagster_dbt_tests/core/dbt_packages
- dagster_dbt/core
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
203 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
| |||
342 | 345 | | |
343 | 346 | | |
344 | 347 | | |
| 348 | + | |
345 | 349 | | |
346 | 350 | | |
347 | 351 | | |
| |||
362 | 366 | | |
363 | 367 | | |
364 | 368 | | |
| 369 | + | |
365 | 370 | | |
366 | 371 | | |
367 | 372 | | |
| |||
378 | 383 | | |
379 | 384 | | |
380 | 385 | | |
| 386 | + | |
381 | 387 | | |
382 | 388 | | |
383 | 389 | | |
384 | | - | |
| 390 | + | |
385 | 391 | | |
386 | 392 | | |
387 | 393 | | |
| |||
393 | 399 | | |
394 | 400 | | |
395 | 401 | | |
396 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
397 | 405 | | |
398 | 406 | | |
399 | 407 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| |||
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
294 | 298 | | |
295 | 299 | | |
296 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
297 | 376 | | |
298 | 377 | | |
299 | 378 | | |
| |||
0 commit comments