Repository: dbt-labs/dbt-snowflake
Pull request #946 (2024-03-21 15:35:45)

[Backport 1.7.latest] Add test and move semantics.
Backport 73b6a1203c305424370de3fc1bd511fe39b0a9c8 from #913.


Patch:
diff --git a/.changes/unreleased/Under the Hood-20240227-010428.yaml b/.changes/unreleased/Under the Hood-20240227-010428.yaml
new file mode 100644
index 0000000..5252d03
--- /dev/null
+++ b/.changes/unreleased/Under the Hood-20240227-010428.yaml
@@ -0,0 +1,6 @@
+kind: Under the Hood
+body: Add unit test for transaction semantics.
+time: 2024-02-27T01:04:28.713433-08:00
+custom:
+  Author: versusfacit
+  Issue: "912"
diff --git a/dbt/adapters/snowflake/relation.py b/dbt/adapters/snowflake/relation.py
index 9d6182a..8c93de6 100644
--- a/dbt/adapters/snowflake/relation.py
+++ b/dbt/adapters/snowflake/relation.py
@@ -1,5 +1,5 @@
 from dataclasses import dataclass, field
-from typing import Optional, Type
+from typing import FrozenSet, Optional, Type
 
 from dbt.adapters.base.relation import BaseRelation
 from dbt.adapters.relation_configs import RelationConfigChangeAction, RelationResults
@@ -20,13 +20,24 @@ from dbt.adapters.snowflake.relation_configs import (
 class SnowflakeRelation(BaseRelation):
     type: Optional[SnowflakeRelationType] = None  # type: ignore
     quote_policy: SnowflakeQuotePolicy = field(default_factory=lambda: SnowflakeQuotePolicy())
-    renameable_relations = frozenset({SnowflakeRelationType.Table, SnowflakeRelationType.View})
-    replaceable_relations = frozenset(
-        {
-            SnowflakeRelationType.DynamicTable,
-            SnowflakeRelationType.Table,
-            SnowflakeRelationType.View,
-        }
+
+    renameable_relations: FrozenSet[SnowflakeRelationType] = field(
+        default_factory=lambda: frozenset(
+            {
+                SnowflakeRelationType.Table,
+                SnowflakeRelationType.View,
+            }
+        )
+    )
+
+    replaceable_relations: FrozenSet[SnowflakeRelationType] = field(
+        default_factory=lambda: frozenset(
+            {
+                SnowflakeRelationType.DynamicTable,
+                SnowflakeRelationType.Table,
+                SnowflakeRelationType.View,
+            }
+        )
     )
 
     @property
diff --git a/dbt/include/snowflake/macros/relations/dynamic_table/create.sql b/dbt/include/snowflake/macros/relations/dynamic_table/create.sql
index 8e8f328..1d76c41 100644
--- a/dbt/include/snowflake/macros/relations/dynamic_table/create.sql
+++ b/dbt/include/snowflake/macros/relations/dynamic_table/create.sql
@@ -6,6 +6,5 @@
         as (
             {{ sql }}
         )
-    ;
 
 {%- endmacro %}


Test patch:
diff --git a/tests/unit/test_renamed_relations.py b/tests/unit/test_renamed_relations.py
new file mode 100644
index 0000000..315d5f3
--- /dev/null
+++ b/tests/unit/test_renamed_relations.py
@@ -0,0 +1,17 @@
+from dbt.adapters.snowflake.relation import SnowflakeRelation
+from dbt.adapters.snowflake.relation_configs import SnowflakeRelationType
+
+
+def test_renameable_relation():
+    relation = SnowflakeRelation.create(
+        database="my_db",
+        schema="my_schema",
+        identifier="my_table",
+        type=SnowflakeRelationType.Table,
+    )
+    assert relation.renameable_relations == frozenset(
+        {
+            SnowflakeRelationType.Table,
+            SnowflakeRelationType.View,
+        }
+    )