Skip to content

Support defining custom callbacks alongside the WATCHER_KUBERNETES callback#2307

Merged
tatiana merged 5 commits into
astronomer:mainfrom
johnhoran:watcher-refactor
Jan 30, 2026
Merged

Support defining custom callbacks alongside the WATCHER_KUBERNETES callback#2307
tatiana merged 5 commits into
astronomer:mainfrom
johnhoran:watcher-refactor

Conversation

@johnhoran
Copy link
Copy Markdown
Contributor

@johnhoran johnhoran commented Jan 30, 2026

Description

I am also setting callbacks on the watcher producer, and the code as it is tries to set them exclusively. So just checking to see if the task already has some and adding the watcher pattern to the callback if it does.

Related Issue(s)

Breaking Change?

Checklist

  • I have made corresponding changes to the documentation (if required)
  • I have added tests that prove my fix is effective or that my feature works

@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 30, 2026

Deploy Preview for astronomer-cosmos canceled.

Name Link
🔨 Latest commit 19ed07b
🔍 Latest deploy log https://app.netlify.com/projects/astronomer-cosmos/deploys/697cb45275debd000820232d

@johnhoran johnhoran marked this pull request as ready for review January 30, 2026 11:25
Copilot AI review requested due to automatic review settings January 30, 2026 11:25
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

This PR updates the Kubernetes watcher producer operator so that it no longer overwrites existing callbacks, but instead augments them with the watcher-specific callback.

Changes:

  • Modifies DbtProducerWatcherKubernetesOperator.__init__ to append WatcherKubernetesCallback to any existing callbacks kwarg instead of passing it exclusively.
  • Leaves the rest of the watcher Kubernetes operator behavior (retry handling, pod manager, execution flow) unchanged.

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

Comment thread cosmos/operators/watcher_kubernetes.py Outdated
Comment thread cosmos/operators/watcher_kubernetes.py Outdated
kwargs["retries"] = 0

super().__init__(task_id=task_id, *args, callbacks=WatcherKubernetesCallback, **kwargs)
kwargs["callbacks"] = kwargs.get("callbacks", []) + [WatcherKubernetesCallback]
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The updated initialization now conditionally appends WatcherKubernetesCallback to any user-provided callbacks, but there is no unit test asserting that both callbacks are preserved (e.g., when setup_operator_args passes custom Kubernetes callbacks). Given the importance of these callbacks for log processing and watcher behavior, consider adding a test that constructs DbtProducerWatcherKubernetesOperator with existing callbacks and verifies the resulting callbacks attribute includes both the user-defined and watcher callbacks in the expected order.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tatiana
Copy link
Copy Markdown
Collaborator

tatiana commented Jan 30, 2026

Thanks a lot for this improvement, @johnhoran !

@tatiana tatiana changed the title Watcher callbacks Support defining custom callbacks alongside the ExecutionMode.WATCHER_KUBERNETES callback Jan 30, 2026
@tatiana tatiana changed the title Support defining custom callbacks alongside the ExecutionMode.WATCHER_KUBERNETES callback Support defining custom callbacks alongside the WATCHER_KUBERNETES callback Jan 30, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.12%. Comparing base (2ca20e4) to head (19ed07b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2307   +/-   ##
=======================================
  Coverage   98.12%   98.12%           
=======================================
  Files         100      100           
  Lines        6725     6733    +8     
=======================================
+ Hits         6599     6607    +8     
  Misses        126      126           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

tatiana added a commit that referenced this pull request Jan 30, 2026
@tatiana tatiana mentioned this pull request Jan 30, 2026
Copy link
Copy Markdown
Collaborator

@tatiana tatiana left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the improvement, @johnhoran ! We'll release this as part of Cosmos 1.13.0

@pankajastro pankajastro added this to the Cosmos 1.13.0 milestone Jan 30, 2026
@tatiana tatiana merged commit d8ecb0a into astronomer:main Jan 30, 2026
90 checks passed
Copy link
Copy Markdown
Contributor

@pankajkoti pankajkoti left a comment

Choose a reason for hiding this comment

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

LGTM

@pankajastro pankajastro mentioned this pull request Jan 30, 2026
tatiana added a commit that referenced this pull request Jan 30, 2026
Features

* Support cross-referencing models across dbt projects using dbt-loom by
@pankajkoti in #2271
* Support use of YAML selectors when using ``LoadMode.DBT_MANIFEST`` by
@YourRoyalLinus in #2261
* Introduce ``ExecutionMode.WATCHER_KUBERNETES`` to use the watcher with
``KubernetesPodOperator`` by @tatiana in #2207
* Add support for StarRocks profile mapping by @kurkim0661 in #2256
* Allow pushing URIs as XComs for Cosmos tasks by @corsettigyg in #2275
* Support defining custom callbacks alongside the ``WATCHER_KUBERNETES``
callback by @johnhoran in #2307

Enhancements

* Refactor: remove duplicate ``_construct_dest_file_path`` by @jx2lee in
#2077
* Leverage Airflow ``::group::`` to group logs associated with DAG
parsing by @tatiana in #2235
* Refactor ``DbtConsumerWatcherSensor`` for reusability by @tatiana in
#2245
* Restore plain text output when using ``ExecutionMode.WATCHER`` by
@tiovader in #2241

Bug Fixes

* Fix running empty models or ephemeral nodes in
``ExecutionMode.WATCHER`` by @tatiana in #2279
* Improve watcher producer task priority in scheduling and the UI by
@tatiana in #2237
* Fix typos and formatting issues in documentation by @pankajkoti in
#2259
* Allow watcher producer retries without erroring by @tatiana in #2283
* Fix ``TestBehavior.AFTER_ALL`` is missing project_name information
when loading project using manifest file by @tuantran0910 in #2242
* Fix duplicate log lines in watcher subprocess execution and format
timestamps by @pankajkoti in #2301

Docs

* Add Watcher Kubernetes documentation by @tatiana in #2303
* Document newly added telemetry metrics in the privacy notice by
@pankajkoti in #2249
* Add compatibility policy document by @pankajastro in #2251
* Improve watcher documentation related to dbt threads by @tatiana in
#2273
* Fix link in watcher execution mode documentation by @jedcunningham in
#2277
* Update Apache Airflow minimum compatibility policy by @tatiana in
#2285
* Clarify Cosmos runtime support until "End of Basic Support" by
@jedcunningham in #2286
* Update watcher docs by @tatiana in #2298
* Update watcher kubernetes documentation by @tatiana in #2306

Others

* Add Airflow 3 DAG versioning tests for Cosmos by @michal-mrazek in
#2177
* Add dbt Core 1.11 to the test matrix by @tatiana in #2230
* Add integration tests using InvocationMode.SUBPROCESS and validate
output by @tatiana in #2287
* Fix main branch failing tests by @tatiana in #2296
* Update pre-commit hooks to the latest versions by @jedcunningham in
#2289
* Pre-commit autoupdates by @pre-commit in #2222, #2264, #2274 and #2290
* Dependabot updates by @dependabot in #2218, #2219, #2220, #2280 and
#2284
* Add Scarf metrics to understand Cosmos feature usage patterns
- Add telemetry tracking for dbt docs plugin usage by @pankajkoti in
#2240
- Add DAG run telemetry metrics for load mode, invocation, and
render_config parameters by @pankajkoti in #2223
  - Collect profile metrics for DAG runs by @pankajastro in #2228
- Compress telemetry metadata to reduce serialized DAG size by
@pankajkoti in #2252
- Skip storing telemetry metadata when emission is disabled by
@pankajkoti in #2278
- Hide telemetry metadata parameters from the Airflow trigger UI by
@pankajkoti in #2247

closes:
astronomer/oss-integrations-private#317

---------

Co-authored-by: Tatiana Al-Chueyr <tatiana.alchueyr@gmail.com>
tatiana added a commit that referenced this pull request Feb 2, 2026
tatiana added a commit that referenced this pull request Feb 20, 2026
(cherry picked from commit 0f6efed)
@tatiana tatiana mentioned this pull request Feb 20, 2026
tatiana added a commit that referenced this pull request Feb 25, 2026
**Enhancements**

* Change Snowflake profile mappings to default to four threads by
@tatiana in #2374
* Refactor to avoid potential future ``UnboundLocalError`` for
``producer_task`` in ``calculate_tasks_map`` by @rin in #2309

**Bug Fixes**

* Fix graph selector when using + selector with ``dbt-loom`` by
@award1230 in #2389
* Populate ``compiled_sql`` for ``InvocationMode.SUBPROCESS`` in
``ExecutionMode.WATCHER`` by @pankajkoti in #2319
* Preserve ``extra_context`` for watcher consumer task instances by
@pankajkoti in #2381
* Fix watcher: respect ``deferrable=False`` from ``operator_args`` on
consumer sensor by @pankajkoti in #2384
* Error handle invalid YAML with ``LoadMode.DBT_MANIFEST`` and
``RenderConfig.selector`` by @jonbillings in #2316
* Fix selecting model when it has the same name as folder by
@pankajastro in #2328
* Handle Param Validation errors by @tatiana in #2358
* Fix cache swap issue by @jonbillings in #2332
* Fix leaked semaphore warnings in Airflow 3 by resetting dbt adapters
by @pankajkoti in #2335

**Docs**

* Document ``ExecutionMode.KUBERNETES`` limitations by @tatiana in #2326

**Others**

* Add .airflow-registry.yaml for Airflow Provider Registry by @kaxil in
#2387
* Improve test coverage for PR #2307 by @tatiana in #2308
* Address feedback from code review #2389 by @evanvolgas in #2394

Closes:
astronomer/oss-integrations-private#333
@tatiana tatiana mentioned this pull request Feb 25, 2026
tatiana added a commit that referenced this pull request Feb 25, 2026
Enhancements

* Change Snowflake profile mappings to default to four threads by
@tatiana in #2374
* Refactor to avoid potential future ``UnboundLocalError`` for
``producer_task`` in ``calculate_tasks_map`` by @rin in #2309

Bug Fixes

* Fix graph selector when using + selector with ``dbt-loom`` by
@award1230 in #2389
* Populate ``compiled_sql`` for ``InvocationMode.SUBPROCESS`` in
``ExecutionMode.WATCHER`` by @pankajkoti in #2319
* Preserve ``extra_context`` for watcher consumer task instances by
@pankajkoti in #2381
* Fix watcher: respect ``deferrable=False`` from ``operator_args`` on
consumer sensor by @pankajkoti in #2384
* Error handle invalid YAML with ``LoadMode.DBT_MANIFEST`` and
``RenderConfig.selector`` by @YourRoyalLinus in #2316
* Fix selecting model when it has the same name as folder by
@pankajastro in #2328
* Handle Param Validation errors by @tatiana in #2358
* Fix cache swap issue by @YourRoyalLinus in #2332
* Fix leaked semaphore warnings in Airflow 3 by resetting dbt adapters
by @pankajkoti in #2335

Docs

* Document ``ExecutionMode.KUBERNETES`` limitations by @tatiana in #2326

Others

* Add .airflow-registry.yaml for Airflow Provider Registry by @kaxil in
#2387
* Improve test coverage for PR #2307 by @tatiana in #2308
* Address feedback from code review #2389 by @evanvolgas in #2394

Additional details on this change:
- The actual release was done from branch 1.13:
https://github.com/astronomer/astronomer-cosmos/releases/tag/astronomer-cosmos-v1.13.1
- This PR aims to update our CHANGELOG, and allow us to give credit to
the username that was being questioned by codespell
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.

5 participants