fix: warn when documented columns are missing from the relation in persist_docs
Resolves #
Description
When persist_docs.columns is enabled, DatabricksAdapter.get_persist_doc_columns only iterates the columns that actually exist in the materialized relation. As a result, any column documented in a model's schema.yml that is not present in the relation (typo, renamed column, stale docs) is silently skipped — no comment is applied and no feedback is given to the user.
This PR adds a warning that names those columns. The filtering behavior is unchanged (the missing columns are still skipped so the ALTER never errors); we just surface them via warn_or_error, so it respects --warn-error like other adapter warnings.
This ports the behavior added upstream in dbt-adapters — dbt-labs/dbt-adapters#1684 (closes dbt-labs/dbt-adapters#1690). Because dbt-databricks overrides persist_docs with its own native get_persist_doc_columns, the upstream macro change does not reach this adapter, so the warning is added here directly.
Example warning:
The following columns are specified in the schema but are not present in the database and will be skipped: col2
Checklist
- [x] I have run this code in development and it appears to resolve the stated issue
- [x] This PR includes tests, or tests are not required/relevant for this PR
- [x] I have updated the
CHANGELOG.mdand added information about my change to the "dbt-databricks next" section.
Coverage report
This report was generated by python-coverage-comment-action
Click to see where and how coverage changed
File Statements Missing Coverage Coverage
(new stmts)Lines missing
dbt/adapters/databricks
impl.py
911-912, 1003-1004
persist_doc_column_warnings.py
dbt/adapters/databricks/relation_configs
column_comments.py
Project Total
@r-jais — follow-up coverage review of this PR at head a248840e. Sharing so you can decide what to fix here versus document as out of scope / follow-up.
Coverage report: missing-column persist_docs warning
Scenario reviewed: exactly persist_docs: {columns: true} (with relation unset/false) plus a YAML column that is not present on the relation/query.
Overall: PARTIAL
Important config caveat:
ColumnCommentsProcessor.from_relation_configcurrently derives itspersistflag frompersist_docs.relation, notpersist_docs.columns. The matrix below follows the stated columns-only scenario; outcomes that change when both flags are enabled are listed separately.
Matrix — columns: true, relation: false
| Materialization | Scenario | Verdict | Path |
|---|---|---|---|
| table | V1 create/replace | WARNS | persist_docs → get_persist_doc_columns |
| table | V2 create/replace | SILENT | create_table_at → parse_columns_and_constraints |
| incremental | V1 create/full refresh | WARNS | post-create persist_docs |
| incremental | V1 subsequent, config changes on | WARNS once | typed diff is gated off; later persist_docs warns |
| incremental | V1 subsequent, config changes off | WARNS once | config diff is skipped; persist_docs still runs |
| incremental | V2 create/full refresh | SILENT | create_table_at → parse_columns_and_constraints |
| incremental | V2 subsequent, config changes on | SILENT | ColumnCommentsConfig.persist is false because relation is false |
| incremental | V2 subsequent, config changes off | SILENT | no config diff and no persist_docs fallback |
| view | V1 create/replace | SILENT | get_persist_docs_column_list iterates query columns only |
| view | V2 create/replace_with_view |
SILENT | same shared create helper |
| view | V2 comment-only alter | SILENT | typed diff is gated off by relation: false |
| view | V2 query-changing alter/reapply | WARNS once | get_persist_doc_columns after ALTER VIEW AS |
| snapshot | after materialize | WARNS | persist_docs |
| clone | table path | WARNS | persist_docs |
| clone | view fallback | SILENT | shared view-create helper |
| seed | create/reset | SILENT | iterates agate/query columns only |
| materialized_view | create/replace/full refresh | SILENT | parse_columns_and_constraints |
| materialized_view | in-place alter | N/A | no ColumnCommentsProcessor |
| streaming_table | create/replace/full refresh | SILENT | parse_columns_and_constraints |
| streaming_table | in-place alter | N/A | no ColumnCommentsProcessor |
I removed the headline counts because the earlier matrix combined multiple scenarios and flag combinations, making the totals non-reproducible.
Outcomes when both relation: true and columns: true
These rows change:
- V1 incremental subsequent, config changes on → DOUBLE warning risk. It runs
model_config.get_changeset(...)and laterpersist_docs. - V2 incremental subsequent, config changes on → WARNS. The typed
get_diffgate is now enabled. - V2 view comment-only alter → WARNS. The typed
get_diffgate is now enabled. - V2 view query-changing alter/reapply → DOUBLE warning risk. Config diff warns, then query reapplication calls
get_persist_doc_columns.
The wrong-key gate also has the inverse effect: relation: true, columns: false can warn through the typed diff even though column persistence is disabled. Fixing the gate is therefore needed to avoid both false negatives and false positives.
What this PR already covers well
- V1 table/incremental/snapshot/clone-table paths through
get_persist_doc_columns - Relation-config diff paths when their current
persistgate is enabled - V2 view query reapplication through
get_persist_doc_columns - Filtering missing columns out of the V2 alter diff so no ALTER targets a nonexistent column
Highest-priority gaps to consider
- V2 table/incremental create-time —
parse_columns_and_constraintsnever warns; first create and full refresh remain silent. - View create (V1 + V2) —
get_persist_docs_column_listiterates query columns only, so YAML-only columns remain silent. - Typed persist gate —
ColumnCommentsProcessorshould gate column comments onpersist_docs.columns, notpersist_docs.relation. - V2 +
incremental_apply_config_changes: false— skipsget_diffwith no V1-stylepersist_docsfallback. - Duplicate warnings — warning in multiple low-level comparison helpers can emit twice during one model run.
Suggested next steps
- If keeping the current scope: narrow the PR description/CHANGELOG to the comparison points actually covered, and call out typed-create and view-create as follow-ups.
- If expanding scope here: centralize or otherwise deduplicate the missing-column warning; fix the typed gate to use
columns; cover view create; and gate any typed-create warning explicitly onconfig.persist_column_docs(). - Do not add an unconditional warning inside
parse_columns_and_constraints: that helper runs even when column persistence is disabled, and--warn-errorwould turn those false positives into failures.
Happy to clarify any row in the matrix if useful.
@r-jais — follow-up coverage review of this PR at head
a248840e. Sharing so you can decide what to fix here versus document as out of scope / follow-up.
I would also recommend to add functional tests to verify on behaviour as well as there can be cases on Silent/Double warnings so need to balance coverage/correctness
Overall changes look good, there is still a case where warning can come twice. Have documented it here with the fix --> https://github.com/r-jais/dbt-databricks/compare/fix/persist-docs-warn-missing-columns...databricks:dbt-databricks:sd-db/persist-docs-single-missing-col-warn (do check if this approach looks good)
@sd-db Applied your branch, looks good!