Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADAP-923: Resolve issue where backup parameter was inadvertently considered in configuration change monitoring #657

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20231103-181357.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix handling of `backup` parameter during config change monitoring
time: 2023-11-03T18:13:57.401994-04:00
custom:
Author: mikealfare
Issue: "621"
7 changes: 0 additions & 7 deletions dbt/adapters/redshift/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
RedshiftMaterializedViewConfig,
RedshiftMaterializedViewConfigChangeset,
RedshiftAutoRefreshConfigChange,
RedshiftBackupConfigChange,
RedshiftDistConfigChange,
RedshiftSortConfigChange,
RedshiftIncludePolicy,
Expand Down Expand Up @@ -93,12 +92,6 @@ def materialized_view_config_changeset(
context=new_materialized_view.autorefresh,
)

if new_materialized_view.backup != existing_materialized_view.backup:
config_change_collection.backup = RedshiftBackupConfigChange(
action=RelationConfigChangeAction.alter,
context=new_materialized_view.backup,
)

if new_materialized_view.dist != existing_materialized_view.dist:
config_change_collection.dist = RedshiftDistConfigChange(
action=RelationConfigChangeAction.alter,
Expand Down
1 change: 0 additions & 1 deletion dbt/adapters/redshift/relation_configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from dbt.adapters.redshift.relation_configs.materialized_view import (
RedshiftMaterializedViewConfig,
RedshiftAutoRefreshConfigChange,
RedshiftBackupConfigChange,
RedshiftMaterializedViewConfigChangeset,
)
from dbt.adapters.redshift.relation_configs.policies import (
Expand Down
16 changes: 2 additions & 14 deletions dbt/adapters/redshift/relation_configs/materialized_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Optional, Set

import agate
Expand Down Expand Up @@ -56,7 +56,7 @@ class RedshiftMaterializedViewConfig(RedshiftRelationConfigBase, RelationConfigV
schema_name: str
database_name: str
query: str
backup: bool = True
backup: bool = field(default=True, compare=False, hash=False)
dist: RedshiftDistConfig = RedshiftDistConfig(diststyle=RedshiftDistStyle.even)
sort: RedshiftSortConfig = RedshiftSortConfig()
autorefresh: bool = False
Expand Down Expand Up @@ -241,18 +241,8 @@ def requires_full_refresh(self) -> bool:
return False


@dataclass(frozen=True, eq=True, unsafe_hash=True)
class RedshiftBackupConfigChange(RelationConfigChange):
context: Optional[bool] = None

@property
def requires_full_refresh(self) -> bool:
return True


@dataclass
class RedshiftMaterializedViewConfigChangeset:
backup: Optional[RedshiftBackupConfigChange] = None
dist: Optional[RedshiftDistConfigChange] = None
sort: Optional[RedshiftSortConfigChange] = None
autorefresh: Optional[RedshiftAutoRefreshConfigChange] = None
Expand All @@ -262,7 +252,6 @@ def requires_full_refresh(self) -> bool:
return any(
{
self.autorefresh.requires_full_refresh if self.autorefresh else False,
self.backup.requires_full_refresh if self.backup else False,
self.dist.requires_full_refresh if self.dist else False,
self.sort.requires_full_refresh if self.sort else False,
}
Expand All @@ -272,7 +261,6 @@ def requires_full_refresh(self) -> bool:
def has_changes(self) -> bool:
return any(
{
self.backup if self.backup else False,
self.dist if self.dist else False,
self.sort if self.sort else False,
self.autorefresh if self.autorefresh else False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from dbt.adapters.base.relation import BaseRelation
from dbt.contracts.graph.model_config import OnConfigurationChangeOption

from dbt.tests.adapter.materialized_view.basic import MaterializedViewBasic
from dbt.tests.adapter.materialized_view.changes import (
Expand Down Expand Up @@ -246,7 +247,30 @@ def models(self):
def seeds(self):
return {"my_seed.csv": MY_SEED}

def test_running_mv_with_backup_false_succeeds(self, project):
@pytest.fixture(scope="class")
def project_config_update(self):
return {"models": {"on_configuration_change": OnConfigurationChangeOption.Fail.value}}

@pytest.fixture(scope="function")
def dbt_run_results(self, project):
run_dbt(["seed"])
result = run_dbt(["run"])
assert result[0].node.config_call_dict["backup"] is False
yield run_dbt(["run", "--full-refresh"])

def test_running_mv_with_backup_false_succeeds(self, dbt_run_results):
assert dbt_run_results[0].node.config_call_dict["backup"] is False

def test_running_mv_with_backup_false_is_idempotent(self, project, dbt_run_results):
"""
Addresses: https://github.com/dbt-labs/dbt-redshift/issues/621
Context:
- The default for `backup` is `True`
- We cannot query `backup` for a materialized view in Redshift at the moment
Premise:
- Set `on_configuration_change` = 'fail' (via `project_config_update`)
- Set `backup` = False (via `NO_BACKUP_MATERIALIZED_VIEW`)
- Create the materialized view (via `dbt_run_results`)
- Run a second time forcing the configuration change monitoring
- There should be no changes monitored, hence the run should be successful
"""
results = run_dbt(["run"])
assert results[0].node.config_call_dict["backup"] is False