Skip to content

Commit

Permalink
assert resolver.model is ModelNode prior to resolving event_time_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Nov 5, 2024
1 parent bdf28d7 commit 700de80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def resolve_event_time_filter(self, target: ManifestNode) -> Optional[EventTimeF
os.environ.get("DBT_EXPERIMENTAL_MICROBATCH")
and (isinstance(target.config, NodeConfig) or isinstance(target.config, SourceConfig))
and target.config.event_time
and isinstance(self.model, ModelNode)
and self.model.config.materialized == "incremental"
and self.model.config.incremental_strategy == "microbatch"
):
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/context/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
RuntimeRefResolver,
RuntimeSourceResolver,
)
from dbt.contracts.graph.nodes import ModelNode


class TestBaseResolver:
Expand All @@ -39,12 +40,13 @@ def test_resolve_limit(self, resolver, empty, expected_resolve_limit):
assert resolver.resolve_limit == expected_resolve_limit

@pytest.mark.parametrize(
"dbt_experimental_microbatch,materialized,incremental_strategy,expect_filter",
"dbt_experimental_microbatch,materialized,incremental_strategy,resolver_model_node,expect_filter",
[
(True, "incremental", "microbatch", True),
(False, "incremental", "microbatch", False),
(True, "table", "microbatch", False),
(True, "incremental", "merge", False),
(True, "incremental", "microbatch", True, True),
(True, "incremental", "microbatch", False, False),
(False, "incremental", "microbatch", True, False),
(True, "table", "microbatch", True, False),
(True, "incremental", "merge", True, False),
],
)
def test_resolve_event_time_filter(
Expand All @@ -54,6 +56,7 @@ def test_resolve_event_time_filter(
dbt_experimental_microbatch: bool,
materialized: str,
incremental_strategy: str,
resolver_model_node: bool,
expect_filter: bool,
) -> None:
if dbt_experimental_microbatch:
Expand All @@ -67,6 +70,8 @@ def test_resolve_event_time_filter(
# Resolver mocking
resolver.config.args.EVENT_TIME_END = None
resolver.config.args.EVENT_TIME_START = None
if resolver_model_node:
resolver.model = mock.MagicMock(spec=ModelNode)
resolver.model.config = mock.MagicMock(NodeConfig)
resolver.model.config.materialized = materialized
resolver.model.config.incremental_strategy = incremental_strategy
Expand Down

0 comments on commit 700de80

Please sign in to comment.