From 830eea791f633b9e0c2dd3361cea4346f81fa6f5 Mon Sep 17 00:00:00 2001 From: Pankaj Koti Date: Wed, 24 Dec 2025 15:27:30 +0000 Subject: [PATCH 1/3] Fix DbtSourceWatcherOperator template_fields inheritance DbtSourceWatcherOperator should inherit template_fields from its parent DbtSourceLocalOperator instead of DbtConsumerWatcherSensor. The previous assignment incorrectly included fields like model_unique_id that do not exist on source operators, causing AttributeError when using sources with tests in watcher mode with SourceRenderingBehavior.WITH_TESTS_OR_FRESHNESS. Fixes #2203 --- cosmos/operators/watcher.py | 4 ++-- tests/operators/test_watcher.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cosmos/operators/watcher.py b/cosmos/operators/watcher.py index 3318e25540..eef72d8483 100644 --- a/cosmos/operators/watcher.py +++ b/cosmos/operators/watcher.py @@ -4,7 +4,7 @@ import json import logging import zlib -from collections.abc import Callable +from collections.abc import Callable, Sequence from datetime import timedelta from pathlib import Path from typing import TYPE_CHECKING, Any @@ -502,7 +502,7 @@ class DbtSourceWatcherOperator(DbtSourceLocalOperator): Executes a dbt source freshness command, synchronously, as ExecutionMode.LOCAL. """ - template_fields: tuple[str, ...] = DbtConsumerWatcherSensor.template_fields + template_fields: Sequence[str] = DbtSourceLocalOperator.template_fields # type: ignore[assignment] class DbtRunWatcherOperator(DbtConsumerWatcherSensor): diff --git a/tests/operators/test_watcher.py b/tests/operators/test_watcher.py index cc506495c7..39aee1ed63 100644 --- a/tests/operators/test_watcher.py +++ b/tests/operators/test_watcher.py @@ -1158,3 +1158,16 @@ def test_sensor_and_producer_different_param_values(mock_bigquery_conn): assert task.execution_timeout == timedelta(seconds=2) else: assert task.execution_timeout == timedelta(seconds=1) + + +def test_dbt_source_watcher_operator_template_fields(): + """Test that DbtSourceWatcherOperator doesn't include model_unique_id in template_fields.""" + from cosmos.operators.local import DbtSourceLocalOperator + from cosmos.operators.watcher import DbtSourceWatcherOperator + + # DbtSourceWatcherOperator should NOT have model_unique_id in template_fields + # because it runs locally and doesn't watch models, it executes source freshness + assert "model_unique_id" not in DbtSourceWatcherOperator.template_fields + + # DbtSourceWatcherOperator should inherit template_fields from DbtSourceLocalOperator + assert DbtSourceWatcherOperator.template_fields == DbtSourceLocalOperator.template_fields From 513d1763a0b8ce6c3b12c75efe6023e8fd87818b Mon Sep 17 00:00:00 2001 From: Pankaj Koti Date: Wed, 24 Dec 2025 16:54:58 +0000 Subject: [PATCH 2/3] Bump version to 1.12.1a1 Update version to 1.12.1a1 for alpha release containing the DbtSourceWatcherOperator template_fields fix. --- CHANGELOG.rst | 7 +++++++ cosmos/__init__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f71af2abd9..3590337f1c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ Changelog ========= +1.12.1a1 (2025-12-20) +---------------------- + +Bug Fixes + +* Fix ``DbtSourceWatcherOperator.template_fields`` to inherit from ``DbtSourceLocalOperator`` instead of ``DbtConsumerWatcherSensor`` by @pankajkoti in #2214 + 1.12.0 (2025-12-18) ---------------------- diff --git a/cosmos/__init__.py b/cosmos/__init__.py index d113ba240b..be4f762632 100644 --- a/cosmos/__init__.py +++ b/cosmos/__init__.py @@ -9,7 +9,7 @@ from cosmos import settings -__version__ = "1.12.0" +__version__ = "1.12.1a1" if not settings.enable_memory_optimised_imports: from cosmos.airflow.dag import DbtDag From 05e0b58671373341aee0b00b1c35a69c25c0294e Mon Sep 17 00:00:00 2001 From: Pankaj Koti Date: Fri, 26 Dec 2025 14:44:31 +0530 Subject: [PATCH 3/3] Apply suggestions from code review --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3590337f1c..6716145fbe 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ Changelog ========= -1.12.1a1 (2025-12-20) +1.12.1a1 (2025-12-26) ---------------------- Bug Fixes