Skip to content

use_safer_relation_operations: replacing a view fails with UNRESOLVED_COLUMN when its upstream columns changed in the same run #1714

Open

Description

@eirikmag

Describe the bug

With use_materialization_v2: true and use_safer_relation_operations: true, replacing an existing view goes through safely_replace. That calls create_backup, which issues ALTER VIEW <view> RENAME TO <view>__dbt_backup.

Databricks analyses the old view definition again when it renames a view. If an upstream relation in the same run dropped or renamed a column the old view uses, the rename fails and the build stops:

alter view `cat`.`sch`.`my_view` rename to `cat`.`sch`.`my_view__dbt_backup`

[UNRESOLVED_COLUMN.WITH_SUGGESTION] A column, variable, or function parameter with name `old_col` cannot be resolved. Did you mean one of the following? [...]. SQLSTATE: 42703

That situation is the normal reason a view gets rebuilt: its upstream changed. The failed run leaves the old, broken view in place, so every retry fails the same way until someone drops the view by hand.

Steps to reproduce

  1. Configure dbt_project.yml:
    flags:
      use_materialization_v2: true
    models:
      my_project:
        +use_safer_relation_operations: true
  2. Create a seed s.csv:
    id,old_col
    1,a
    and a view model v.sql:
    {{ config(materialized='view') }}
    select id, old_col from {{ ref('s') }}
    Run dbt build.
  3. Rename the seed column to new_col and update v.sql to select new_col.
  4. Run dbt build --full-refresh -s s+.

The seed is recreated with the new column, then v fails on ALTER VIEW ... RENAME TO ...__dbt_backup with UNRESOLVED_COLUMN.

Without --full-refresh the same thing happens whenever view_update_via_alter is off or the change needs a full replace.

Expected behavior

The view is replaced. A view holds no data, so renaming it to a backup protects nothing, and CREATE OR REPLACE VIEW is already atomic.

Possible fixes in databricks__get_replace_sql (macros/relations/replace.sql):

  • Use get_replace_view_sql (CREATE OR REPLACE VIEW) for view-to-view replaces even when use_safer_relation_operations is on.
  • Or, in safely_replace, drop the existing view instead of renaming it to a backup.

Workaround

Override replace_with_view in the project so that view-to-view replaces call get_replace_view_sql directly. Tables and incrementals keep the safer path.

System information

  • dbt-core: 1.11.7
  • dbt-databricks: 1.12.4 (the code path is unchanged on main / 1.12.7)
  • databricks-sql-connector: 4.4.0
  • Unity Catalog, serverless SQL warehouse
  • OS: Linux (Azure DevOps hosted agent)

Activity

  1. shantanutheone commented on Oct 17, 2026

    @shantanutheone

    Opened #1733 for this, going with the first option you suggested (view to view uses CREATE OR REPLACE VIEW even with safer relation operations on). I don't have a workspace to reproduce it, so it has unit tests plus a functional test that does the column rename from your steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions