From 23880f420ddf73f96d51c47dacb4d063b0151a0f Mon Sep 17 00:00:00 2001 From: Mila Page <67295367+VersusFacit@users.noreply.github.com> Date: Thu, 21 Mar 2024 07:44:08 -0700 Subject: [PATCH] Add test to restore transactions behavior. (#24) Co-authored-by: Mila Page Co-authored-by: Mike Alfare <13974384+mikealfare@users.noreply.github.com> Co-authored-by: Mike Alfare --- .../Under the Hood-20240226-225642.yaml | 6 ++++++ dbt/adapters/postgres/relation.py | 10 +++++----- tests/unit/test_renamed_relations.py | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 .changes/unreleased/Under the Hood-20240226-225642.yaml create mode 100644 tests/unit/test_renamed_relations.py diff --git a/.changes/unreleased/Under the Hood-20240226-225642.yaml b/.changes/unreleased/Under the Hood-20240226-225642.yaml new file mode 100644 index 00000000..dd5d0645 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240226-225642.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Add unit test for transaction semantics. +time: 2024-02-26T22:56:42.202429-08:00 +custom: + Author: versusfacit + Issue: "23" diff --git a/dbt/adapters/postgres/relation.py b/dbt/adapters/postgres/relation.py index 3f659fb4..677b12ac 100644 --- a/dbt/adapters/postgres/relation.py +++ b/dbt/adapters/postgres/relation.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import FrozenSet, Optional, Set from dbt.adapters.base.relation import BaseRelation @@ -20,19 +20,19 @@ @dataclass(frozen=True, eq=False, repr=False) class PostgresRelation(BaseRelation): - renameable_relations = frozenset( + renameable_relations: FrozenSet[RelationType] = field(default_factory=lambda: frozenset( { RelationType.View, RelationType.Table, RelationType.MaterializedView, } - ) - replaceable_relations = frozenset( + )) + replaceable_relations: FrozenSet[RelationType] = field(default_factory=lambda: frozenset( { RelationType.View, RelationType.Table, } - ) + )) def __post_init__(self): # Check for length of Postgres table/view names. diff --git a/tests/unit/test_renamed_relations.py b/tests/unit/test_renamed_relations.py new file mode 100644 index 00000000..49900d8e --- /dev/null +++ b/tests/unit/test_renamed_relations.py @@ -0,0 +1,16 @@ +from dbt.adapters.postgres.relation import PostgresRelation +from dbt.adapters.contracts.relation import RelationType + + +def test_renameable_relation(): + relation = PostgresRelation.create( + database="my_db", + schema="my_schema", + identifier="my_table", + type=RelationType.Table, + ) + assert relation.renameable_relations == frozenset({ + RelationType.View, + RelationType.Table, + RelationType.MaterializedView, + })