Repository navigation
dbt sync: keep per-version descriptions on versioned models - #1841
alexandersundquist wants to merge 12 commits into
Conversation
Each version of a versioned model now keeps its own contract's table and column descriptions. The top level holds the latest version's; a version whose description differs gets it on its own entry, and for a column in an override that also carries the column's data_type (dbt drops it for an overriding version) but not its tests (dbt still runs those). Fixes datacontract#1840 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Looks good overall. Could we cover one edge case before merging? Updating v2’s description can add a column to v1Say the shared column list contains When we sync a new description for Proposed fixCould we add a small
datacontract-cli/datacontract/integration/dbt_sync.py Lines 2264 to 2276 in 086bdaf Proposed helperdef _inherits_top_column(bullet: dict, column_name: str) -> bool:
for item in bullet.get("columns") or []:
if isinstance(item, dict) and "include" in item:
include = item["include"]
exclude = item.get("exclude") or []
included = include in ("*", "all") or (
isinstance(include, list) and column_name in include
)
return included and column_name not in exclude
return True # dbt includes all shared columns when there's no selector. |
|
Nice catch! I'll add a fix for this. |
A version with an include list, such as include: [id], doesn't inherit the other top-level columns. Syncing a description no longer adds such a column to it, and no longer removes a column entry the version declares itself. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
While implementing the fix in the latest commit, I noticed the same problem in the per-version type handling, and it already exists on |
|
@alexandersundquist Thanks, I think this can go into this PR as well! |
…anges The per-version type handling counted versions that exclude a column, or leave it out of an include list. When another version changed the column's type, sync added the column back to them. A version that neither inherits the column nor has its own entry for it is now left out. As a result, a column added in a later version gets its data_type at the top level instead of only in that version's override. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
I added the type fix. One side effect: a column added in a later version now gets its |
jschoedl
left a comment
There was a problem hiding this comment.
Thank you!
3 remarks on the PR:
_set_override_tests removed and re-added data_tests, moving it after the override's other keys, so re-syncing unchanged contracts rewrote the file once. It now replaces the tests in place. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dbt drops the top-level column's properties, including config.tags and config.meta, for a version with its own entry for the column. Those entries now carry a copy of the column's tags and meta, refreshed on every sync, and are still removed once they add nothing beyond it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…n that version On a model without a description, the merge wrote the synced version's description to the top level before the description step ran, which then read it as what the other versions already showed. The step now uses the model description from before the sync. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes #1840.
dbt syncnow gives each version of a versioned model its own table and column descriptions. The top level holds the latest version's descriptions. When another version's description differs, it is written on that version's entry, and for a column in that version's own entry for the column. That entry also carries the column'sdata_type, which dbt doesn't take over from the top level, but not its tests, which dbt does. Once the descriptions agree again, these per-version entries are removed.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
uv run pytest)uv run ruff check --fix && uv run ruff format)