Skip to content

Commit 99d88c1

Browse files
committed
fix: apply column_tags when updating a view via ALTER
A V2 view with view_update_via_alter: true errored with "main is not being called during running model" on a run whose only change was its column tags: databricks__alter_view had no column_tags branch, so the alter macro became a no-op that never called statement('main'). Add the branch so the changed column tags are applied on the alter path, matching the view create path and the table/incremental paths. Closes #1525
1 parent a83c94b commit 99d88c1

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Add catalogs.yml v2 support (requires `use_catalogs_v2: true` in dbt-core) ([1440](https://github.com/databricks/dbt-databricks/pull/1440))
66

77
### Fixes
8+
- Apply column-level `databricks_tags` when a Unity Catalog view is updated via `ALTER` (`view_update_via_alter: true`). A run whose only change was its column tags previously errored with `main is not being called during running model` because the `alter_view` path had no `column_tags` branch; it now applies the changed tags there, matching the view create path. ([#XXXX](https://github.com/databricks/dbt-databricks/pull/XXXX) closes [#1525](https://github.com/databricks/dbt-databricks/issues/1525))
89
- Raise a `DbtRuntimeError` when a Python model job run terminates with a non-success `result_state` (e.g. `FAILED`/`TIMEDOUT`) instead of returning silently ([#1477](https://github.com/databricks/dbt-databricks/pull/1477))
910

1011
### Under the Hood

dbt/include/databricks/macros/relations/view/alter.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{% set tblproperties = changes.get("tblproperties") %}
99
{% set query = changes.get("query") %}
1010
{% set column_comments = changes.get("column_comments") %}
11+
{% set column_tags = changes.get("column_tags") %}
1112
{% if tags %}
1213
{{ apply_tags(target_relation, tags.set_tags) }}
1314
{% endif %}
@@ -20,4 +21,7 @@
2021
{% if column_comments %}
2122
{{ alter_column_comments(target_relation, column_comments.comments) }}
2223
{% endif %}
24+
{% if column_tags %}
25+
{{ apply_column_tags(target_relation, column_tags) }}
26+
{% endif %}
2327
{% endmacro %}

tests/functional/adapter/column_tags/test_column_tags.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ class TestColumnTagsView(ColumnTagsMixin):
116116
relation_type = "view"
117117

118118

119+
@pytest.mark.skip_profile("databricks_cluster")
120+
class TestColumnTagsViewUpdateViaAlter(ColumnTagsMixin):
121+
relation_type = "view"
122+
123+
@pytest.fixture(scope="class")
124+
def project_config_update(self):
125+
# With view_update_via_alter, a subsequent run whose only change is its column
126+
# tags takes the alter_view path instead of a full replace; the changed tags
127+
# must be applied there too.
128+
return {
129+
"flags": {"use_materialization_v2": True},
130+
"models": {"+view_update_via_alter": True},
131+
}
132+
133+
119134
@pytest.mark.skip_profile("databricks_cluster")
120135
class TestColumnTagsTableV1(ColumnTagsMixin):
121136
relation_type = "table"

tests/unit/macros/relations/test_view_macros.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def mocks(self, context):
5252
context["apply_tags"] = Mock()
5353
context["apply_tblproperties"] = Mock()
5454
context["alter_query"] = Mock()
55+
context["apply_column_tags"] = Mock()
5556

5657
def render_alter_view(self, template_bundle, changes):
5758
return self.run_macro(
@@ -84,3 +85,10 @@ def test_macros__alter_view_with_query(self, context, template_bundle):
8485
context["apply_tags"].assert_not_called()
8586
context["apply_tblproperties"].assert_not_called()
8687
context["alter_query"].assert_called_once()
88+
89+
def test_macros__alter_view_with_column_tags(self, context, template_bundle):
90+
self.render_alter_view(template_bundle, {"column_tags": Mock()})
91+
context["apply_tags"].assert_not_called()
92+
context["apply_tblproperties"].assert_not_called()
93+
context["alter_query"].assert_not_called()
94+
context["apply_column_tags"].assert_called_once()

0 commit comments

Comments
 (0)