Skip to content

fix: implicit view schema changes with alter view approach#1358

Open
canbekley wants to merge 2 commits into
databricks:mainfrom
canbekley:fix/alter-view-not-applied-on-implicit-changes
Open

fix: implicit view schema changes with alter view approach#1358
canbekley wants to merge 2 commits into
databricks:mainfrom
canbekley:fix/alter-view-not-applied-on-implicit-changes

Conversation

@canbekley

@canbekley canbekley commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Resolves #1356

Note

Stacked on #1444 (resolves #1357), per maintainer request to split this work. please merge that PR first

Description

Views materialized with view_update_via_alter (v2 materialization) were skipping ALTER VIEW AS whenever dbt's query diff reported no change, so changes in underlying tables (e.g. a new column appearing in a select * source) never propagated to the view.

Fix: force ALTER VIEW AS <query> on every invocation by replacing QueryProcessor with a ViewQueryProcessor whose get_diff always returns self. Drop the no-op branch in the view materialization (always alter, never skip).

With #1357's reapply-after-alter_query block now in place, the existing ColumnCommentsProcessor is also removed from ViewConfig every alter-view run wipes column comments and reapplies them unconditionally, so a separate diff path is no longer needed.

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

@tejassp-db

Copy link
Copy Markdown
Contributor

Thanks for the PR. Will look into it.

@tejassp-db tejassp-db self-assigned this Apr 21, 2026

@tejassp-db tejassp-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are two different fixes - column comments and view refresh, in this PR. Can you please split it into two separate PRs?

{% if column_comments %}
{{ alter_column_comments(target_relation, column_comments.comments) }}
{% if config.persist_column_docs() and model.columns %}
{#-- ALTER VIEW AS <query> will wipe all column comments in a column_list, so we need to reapply them here. --#}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this comment please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the issue described in #1357. basically every ALTER VIEW AS command that changes the view defintion will currently (as of dbr 18.1) drop all existing column comments, without adding them back. this issue already existed, but #1356 makes #1357 strictly worse, because we would run ALTER VIEW AS on every invocation.

@canbekley

Copy link
Copy Markdown
Contributor Author

It looks like there are two different fixes - column comments and view refresh, in this PR. Can you please split it into two separate PRs?

good point, I should definitely split this in two separate PRs. there is going to be an order dependency though, as we would need to merge the column comment fix before the bahavioural changes that enforce ALTER VIEW AS invocations. I will create a new PR for the column comment fix.

@canbekley canbekley force-pushed the fix/alter-view-not-applied-on-implicit-changes branch from d485235 to 1dca899 Compare May 8, 2026 09:06
@canbekley canbekley requested a review from jprakash-db as a code owner May 8, 2026 09:06
@canbekley canbekley changed the title fix: view_update_via_alter drops column comments and misses upstream schema changes fix: implicit view schema changes with alter view approach May 8, 2026
@canbekley canbekley requested a review from tejassp-db May 8, 2026 09:17
@canbekley

Copy link
Copy Markdown
Contributor Author

hi @tejassp-db , this PRs is now split into two dependent PRs: column comment fix in #1444 (which would need to be merged first) and the view schema refresh fix in the PR. I also updated the descriptions accordingly. could you please have another look?

canbekley added 2 commits May 8, 2026 11:31
Signed-off-by: Can Bekleyici <can.bekleyici@deepl.com>
Signed-off-by: Can Bekleyici <can.bekleyici@deepl.com>
@canbekley canbekley force-pushed the fix/alter-view-not-applied-on-implicit-changes branch from 1dca899 to d35b3d4 Compare May 8, 2026 09:35
sd-db added a commit that referenced this pull request Jun 24, 2026
Resolves #1357                                 

Split out from #1358 per maintainer request to land independently of the
#1356 behavior change.

### Description
                     
When `view_update_via_alter` is enabled and the alter path issues `ALTER
VIEW <view> AS <query>`,
Databricks silently drops every persisted column comment. The existing
`if column_comments` block
in `databricks__alter_view` doesn't catch this because the
column-comment diff is computed against
the pre-alter state — when model and existing comments match, the diff
is empty, so nothing
reapplies them after `ALTER VIEW AS` wipes them.

Fix: inside the `query` branch of `databricks__alter_view`, reapply
persisted column comments
after `alter_query`, gated on `config.persist_column_docs()` and
`model.columns`. The pattern
mirrors `databricks__persist_docs`
(`dbt/include/databricks/macros/adapters/persist_docs.sql`).
                
The existing `if column_comments` block is kept — it still handles the
disjoint case where only a
column description changed in `schema.yml` (no query change, so the new
reapply path doesn't run).
This fix becomes load-bearing once #1356 lands and `ALTER VIEW AS` runs
on every invocation, but
the bug exists today on any query change and is worth fixing standalone.
### 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.md` and added information about my
change to the
"dbt-databricks next" section.

Signed-off-by: Can Bekleyici <can.bekleyici@deepl.com>
Co-authored-by: Shubham Dhal <shubham.dhal@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

views with star-select semantics and config 'view_update_via_alter' are not being updated view query updates via alter view wipes column comments

2 participants