Skip to content

Commit

Permalink
[Fix] assert resolver.model is ModelNode prior to resolving event_tim…
Browse files Browse the repository at this point in the history
…e_filter (dbt-labs#10975)
  • Loading branch information
MichelleArk authored Nov 6, 2024
1 parent b95f7a7 commit 30b8a92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20241105-151459.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Fix 'no attribute .config' error when ref-ing a microbatch model from non-Model
context
time: 2024-11-05T15:14:59.002236-05:00
custom:
Author: michelleark
Issue: "10928"
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 30b8a92

Please sign in to comment.