diff --git a/.changes/unreleased/Under the Hood-20240227-020742.yaml b/.changes/unreleased/Under the Hood-20240227-020742.yaml new file mode 100644 index 000000000..f7764706c --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240227-020742.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Add unit test for transaction semantics. +time: 2024-02-27T02:07:42.87704-08:00 +custom: + Author: versusfacit + Issue: "914" diff --git a/dbt/adapters/snowflake/relation.py b/dbt/adapters/snowflake/relation.py index 9d6182a71..8c93de69b 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 @@ 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/dev-requirements.txt b/dev-requirements.txt index c3bc47131..c17e2a3c0 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,6 +1,6 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? -git+https://github.com/dbt-labs/dbt-core.git@1.7.latest#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git@ADAP-9681/fix_renamed_relations_override_pre_1.8#egg=dbt-core&subdirectory=core git+https://github.com/dbt-labs/dbt-core.git@1.7.latest#egg=dbt-tests-adapter&subdirectory=tests/adapter # if version 1.x or greater -> pin to major version diff --git a/tests/unit/test_renamed_relations.py b/tests/unit/test_renamed_relations.py new file mode 100644 index 000000000..315d5f343 --- /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, + } + )