-
Notifications
You must be signed in to change notification settings - Fork 296
override the build command and use run when watcher execution test behavior is set to NONE or AFTER_ALL #2428
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: | |
| task_id = kwargs.pop("task_id", PRODUCER_WATCHER_TASK_ID) | ||
| self.tests_per_model: dict[str, list[str]] = kwargs.pop("tests_per_model", {}) | ||
| self.test_results_per_model: dict[str, list[str]] = {} | ||
| use_run_command = kwargs.pop("use_run_command", False) | ||
| kwargs.setdefault("priority_weight", PRODUCER_WATCHER_DEFAULT_PRIORITY_WEIGHT) | ||
| kwargs.setdefault("weight_rule", WATCHER_TASK_WEIGHT_RULE) | ||
| # Consumer watcher retry logic handles model-level reruns using the LOCAL execution mode; rerunning the producer | ||
|
|
@@ -110,6 +111,10 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: | |
| kwargs["queue"] = watcher_dbt_execution_queue or kwargs.get("queue") or DEFAULT_QUEUE | ||
| super().__init__(task_id=task_id, *args, **kwargs) | ||
|
|
||
| if use_run_command: | ||
| # Override the base command to use the run command | ||
| self.base_cmd = ["run"] | ||
|
|
||
|
Comment on lines
+114
to
+117
|
||
| if self.invocation_mode == InvocationMode.SUBPROCESS: | ||
| self.log_format = "json" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,7 @@ class DbtProducerWatcherKubernetesOperator(DbtBuildKubernetesOperator): | |
|
|
||
| def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
| task_id = kwargs.pop("task_id", "dbt_producer_watcher_operator") | ||
| use_run_command = kwargs.pop("use_run_command", False) | ||
|
|
||
| # Disable retries on producer task | ||
| default_args = dict(kwargs.get("default_args", {}) or {}) | ||
|
|
@@ -99,6 +100,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: | |
| super().__init__(task_id=task_id, *args, **kwargs) | ||
| self.dbt_cmd_flags += ["--log-format", "json"] | ||
|
|
||
| if use_run_command: | ||
| self.base_cmd = ["run"] | ||
|
|
||
|
Comment on lines
+103
to
+105
|
||
| @cached_property | ||
| def pod_manager(self) -> CosmosKubernetesPodManager: | ||
| return CosmosKubernetesPodManager(kube_client=self.client, callbacks=self.callbacks) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1868,15 +1868,15 @@ def test_dbt_task_group_with_watcher_has_correct_dbt_cmd(): | |
| ) | ||
|
|
||
| producer_operator = dag_dbt_task_group_watcher_flags.task_dict["dbt_task_group.dbt_producer_watcher"] | ||
| assert producer_operator.base_cmd == ["build"] | ||
| assert producer_operator.base_cmd == ["run"] | ||
|
|
||
|
Comment on lines
1870
to
1872
|
||
| cmd_flags = producer_operator.add_cmd_flags() | ||
|
|
||
| # Build the command without executing it | ||
| full_cmd, env = producer_operator.build_cmd(context=context, cmd_flags=cmd_flags) | ||
|
|
||
| # Verify the command was built correctly | ||
| assert full_cmd[1] == "build" # dbt build command | ||
| assert full_cmd[1] == "run" # dbt run command (not build) when test_behavior is NONE | ||
| assert "--full-refresh" in full_cmd | ||
|
|
||
|
|
||
|
|
@@ -1923,12 +1923,12 @@ def test_dbt_task_group_with_watcher_has_correct_templated_dbt_cmd(): | |
| # Basic check for producer task | ||
| producer_operator = dag_dbt_task_group_watcher_flags.task_dict["dbt_task_group.dbt_producer_watcher"] | ||
| producer_operator.render_template_fields(context=context) # Render the templated fields | ||
| assert producer_operator.base_cmd == ["build"] | ||
| assert producer_operator.base_cmd == ["run"] | ||
|
|
||
| # Build the command without executing it and verify it was built correctly | ||
| cmd_flags = producer_operator.add_cmd_flags() | ||
| full_cmd, _ = producer_operator.build_cmd(context=context, cmd_flags=cmd_flags) | ||
| assert full_cmd[1] == "build" # dbt build command | ||
| assert full_cmd[1] == "run" # dbt run command (not build) when test_behavior is NONE | ||
|
Comment on lines
1923
to
+1931
|
||
|
|
||
| cmd = " ".join(full_cmd) | ||
| assert "--full-refresh" in full_cmd | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching the watcher producer from
dbt buildtodbt runwhen a selector is set will skip non-model resources (e.g., seeds/snapshots) becausedbt runonly executes models. In WATCHER modes, consumer sensors for seeds/snapshots assume the producer executed those nodes and pushed statuses to XCom, so this can cause sensors to wait/timeout. Consider guardinguse_run_commandbehind a check that the selected nodes are models-only (or raise a clear config error), or use a build-based approach that can still exclude tests with selectors.