Skip to content

Refactor handling of watcher producer-only dbt flags#2717

Merged
tatiana merged 4 commits into
mainfrom
extract-producer-only-flags-constant
May 26, 2026
Merged

Refactor handling of watcher producer-only dbt flags#2717
tatiana merged 4 commits into
mainfrom
extract-producer-only-flags-constant

Conversation

@tatiana
Copy link
Copy Markdown
Collaborator

@tatiana tatiana commented May 21, 2026

Follow-up to #2713 review feedback from @pankajkoti: extract the tuple of dbt flags the watcher consumer must strip from a retry command into a module-level constant.

The constant lives in cosmos/operators/_watcher/base.py, one block above BaseConsumerSensor. Its docstring carries the per-flag rationale (previously buried in _filter_flags's own docstring), so a future contributor adding or removing a flag has one place to look.

🤖 Generated with Claude Code (https://claude.com/claude-code)

tatiana added 3 commits May 20, 2026 22:24
When a watcher consumer task retries via _fallback_to_non_watcher_run,
it copies the producer's add_cmd_flags() output into its own dbt
invocation. The producer hardcodes log_format="json" so it can parse
dbt's structured event stream, but that internal choice was leaking
into the consumer's user-facing retry dbt command, producing raw JSON
in task logs (one structured event per line) instead of dbt's
default formatted text.

Add --log-format to the _filter_flags skip list so the producer's
internal log_format choice does not propagate. Users who want JSON
output on retry can still opt in via
operator_args={"dbt_cmd_flags": ["--log-format", "json"]} —
dbt_cmd_flags is appended by build_cmd outside of this flag pipeline.

Reported when validating example_watcher_downstream_not_skipped's
model_downstream_run retry on the 1.14.2a3 release candidate.
Mirrors example_watcher_downstream_not_skipped but adds
operator_args={"dbt_cmd_flags": ["--log-format", "json"]} so the
consumer's retry dbt command emits JSON-formatted logs. Reuses the
same watcher_downstream_not_skipped dbt project and the same fail-once
sequence, so the two DAGs must not run concurrently.
Address @pankajkoti's follow-up nit on #2713: the tuple of flags the
consumer's retry must drop -- ``--select``, ``--exclude``,
``--log-format`` -- is now named ``_PRODUCER_ONLY_FLAGS`` at module
scope rather than inlined in ``_filter_flags``. The constant carries
the rationale for each flag in its docstring, so a future contributor
adding (or removing) one only needs to touch the tuple plus the
docstring rather than hunt for the literal.

Behaviour is unchanged; the existing watcher unit tests still pass.

🤖 Generated with Claude Code (https://claude.com/claude-code)
@tatiana tatiana requested review from a team, corsettigyg, dwreeves and jbandoro as code owners May 21, 2026 09:25
@tatiana tatiana requested review from pankajastro and pankajkoti and removed request for a team May 21, 2026 09:25
Base automatically changed from fix/watcher-retry-log-format to main May 21, 2026 09:25
@tatiana tatiana changed the title Refactor to improve handling of watcher producer-only dbt flags Refactor handling of watcher producer-only dbt flags May 21, 2026
Copilot AI review requested due to automatic review settings May 26, 2026 10:42
@tatiana tatiana merged commit a08f66d into main May 26, 2026
1 check passed
@tatiana tatiana deleted the extract-producer-only-flags-constant branch May 26, 2026 10:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors dbt producer-only flag filtering by introducing a module-level constant and simplifying the _filter_flags docstring.

Changes:

  • Added _PRODUCER_ONLY_FLAGS constant to centralize the list of filtered dbt flags.
  • Updated _filter_flags documentation to reference the centralized constant.
  • Replaced the inline tuple literal with _PRODUCER_ONLY_FLAGS in the filtering logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"""Filter out dbt flags that should not propagate from the producer to the consumer's retry.

The set of stripped flags is defined by ``_PRODUCER_ONLY_FLAGS`` at module
scope; see that constant's docstring for the rationale per flag.
Comment on lines +404 to +408
# default to text. Each entry consumes the following token as its value (e.g.
# ``--log-format json``).
_PRODUCER_ONLY_FLAGS: tuple[str, ...] = ("--select", "--exclude", "--log-format")


else:
continue # skip value of previous flag
if token in ("--select", "--exclude", "--log-format"):
if token in _PRODUCER_ONLY_FLAGS:
@tatiana tatiana added this to the Cosmos 1.15.0 milestone May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants