Skip to content

Commit

Permalink
Add test to ensure a bad incremental strategy results in an error on run
Browse files Browse the repository at this point in the history
Right now, this test will fail. That is because the fix will be in the
next commit. Presently if an incremental model is being built for the
first time (because the relation in the data warehouse doesn't exist)
or if the incremental model is being run as a full refresh, then validation
that the incremental strategy _doesn't happen_. Technically for _most_
incremental strategies, this is "okay" because the incremental strategy
isn't used when creating the relation for the first time or during full
refresh. The exception is the microbatch strategy, which is part of the
problem. The other part of the problem is that this leads to an experience
where if you write up an incremental model (with an invalid strategy) and
then run it to ensure it works, you won't know anything is wrong until it
is run for the second time.
  • Loading branch information
QMalcolm committed Oct 16, 2024
1 parent 10e6d59 commit 037ef1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dbt-tests-adapter/dbt/tests/adapter/basic/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@
{{ config(materialized="incremental") }}
"""

config_materialized_incremental_invalid_strategy = """
{{ config(materialized="incremental", incremental_strategy="bad_strategy") }}
"""

config_materialized_var = """
{{ config(materialized=var("materialized_var", "table"))}}
"""
Expand Down Expand Up @@ -217,3 +221,4 @@
ephemeral_view_sql = config_materialized_view + model_ephemeral
ephemeral_table_sql = config_materialized_table + model_ephemeral
incremental_sql = config_materialized_incremental + model_incremental
incremental_invalid_strategy_sql = config_materialized_incremental_invalid_strategy + model_incremental
25 changes: 25 additions & 0 deletions dbt-tests-adapter/dbt/tests/adapter/basic/test_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,35 @@ def test_incremental_not_schema_change(self, project):

assert run_result == RunStatus.Success

class BaseIncrementalBadStrategy:
@pytest.fixture(scope="class")
def project_config_update(self):
return {"name": "incremental"}

@pytest.fixture(scope="class")
def models(self):
return {"incremental.sql": files.incremental_invalid_strategy_sql,}

@pytest.fixture(scope="class")
def seeds(self):
return {"base.csv": files.seeds_base_csv, "added.csv": files.seeds_added_csv}

def test_incremental_invalid_strategy(self, project):
# seed command
results = run_dbt(["seed"])
assert len(results) == 2

# try to run the incremental model, it should fail on the first attempt
results = run_dbt(["run"], expect_pass=False)


class Testincremental(BaseIncremental):
pass


class TestBaseIncrementalNotSchemaChange(BaseIncrementalNotSchemaChange):
pass


class TestBaseIncrementalBadStrategy(BaseIncrementalBadStrategy):
pass

0 comments on commit 037ef1b

Please sign in to comment.