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

[Fix] assert resolver.model is ModelNode prior to resolving event_time_filter #10975

Merged
merged 2 commits into from
Nov 6, 2024
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
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
Loading