Skip to content

Fix TypeError in Watcher mode with subprocess invocation#2227

Merged
pankajkoti merged 1 commit into
mainfrom
fix/watcher-subprocess-process-log-line-callback-binding
Dec 26, 2025
Merged

Fix TypeError in Watcher mode with subprocess invocation#2227
pankajkoti merged 1 commit into
mainfrom
fix/watcher-subprocess-process-log-line-callback-binding

Conversation

@pankajkoti
Copy link
Copy Markdown
Contributor

When using ExecutionMode.WATCHER with InvocationMode.SUBPROCESS, the _process_log_line_callable was being incorrectly bound as a method when accessed through an instance. This caused Python's descriptor protocol to pass 'self' as the first argument, resulting in:

TypeError: _store_dbt_resource_status_from_log() takes 2 positional arguments but 3 were given

The fix wraps the function with staticmethod() to prevent binding when accessed via self._process_log_line_callable.

Also adds comprehensive tests for the _store_dbt_resource_status_from_log function and verifies the callable is not bound as a method.

closes: #2224

When using ExecutionMode.WATCHER with InvocationMode.SUBPROCESS, the
_process_log_line_callable was being incorrectly bound as a method when
accessed through an instance. This caused Python's descriptor protocol
to pass 'self' as the first argument, resulting in:

TypeError: _store_dbt_resource_status_from_log() takes 2 positional
arguments but 3 were given

The fix wraps the function with staticmethod() to prevent binding when
accessed via self._process_log_line_callable.

Also adds comprehensive tests for the _store_dbt_resource_status_from_log
function and verifies the callable is not bound as a method.
@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 26, 2025

Deploy Preview for astronomer-cosmos canceled.

Name Link
🔨 Latest commit 128f0e7
🔍 Latest deploy log https://app.netlify.com/projects/astronomer-cosmos/deploys/694e38cd434667000842954b

@pankajkoti pankajkoti marked this pull request as ready for review December 26, 2025 07:40
Copilot AI review requested due to automatic review settings December 26, 2025 07:40
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 fixes a TypeError that occurred when using ExecutionMode.WATCHER with InvocationMode.SUBPROCESS. The issue was caused by Python's descriptor protocol incorrectly binding _process_log_line_callable as a method when accessed through an instance, resulting in an extra self argument being passed.

Key changes:

  • Wrapped _process_log_line_callable with staticmethod() to prevent method binding
  • Added comprehensive test coverage for _store_dbt_resource_status_from_log function
  • Added integration tests to verify the callable is not bound as a method

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cosmos/operators/watcher.py Applied staticmethod() wrapper to _process_log_line_callable to prevent method binding
tests/operators/test_watcher.py Added new test class TestStoreDbStatusFromLog with comprehensive unit and integration tests

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

Comment thread tests/operators/test_watcher.py
Comment thread cosmos/operators/watcher.py
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.98%. Comparing base (057be02) to head (128f0e7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2227      +/-   ##
==========================================
- Coverage   97.98%   97.98%   -0.01%     
==========================================
  Files          95       95              
  Lines        6190     6189       -1     
==========================================
- Hits         6065     6064       -1     
  Misses        125      125              

☔ 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.

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 for fixing this, @pankajkoti ! Looks great

@pankajkoti pankajkoti merged commit 24508c1 into main Dec 26, 2025
88 checks passed
@pankajkoti pankajkoti deleted the fix/watcher-subprocess-process-log-line-callback-binding branch December 26, 2025 09:12
@pankajkoti pankajkoti added this to the 1.12.1 milestone Dec 26, 2025
pankajkoti added a commit that referenced this pull request Dec 29, 2025
When using ExecutionMode.WATCHER with InvocationMode.SUBPROCESS, the
_process_log_line_callable was being incorrectly bound as a method when
accessed through an instance. This caused Python's descriptor protocol
to pass 'self' as the first argument, resulting in:

TypeError: _store_dbt_resource_status_from_log() takes 2 positional
arguments but 3 were given

The fix wraps the function with staticmethod() to prevent binding when
accessed via self._process_log_line_callable.

Also adds comprehensive tests for the
_store_dbt_resource_status_from_log function and verifies the callable
is not bound as a method.

closes: #2224
@pankajkoti pankajkoti mentioned this pull request Dec 29, 2025
tatiana added a commit that referenced this pull request Jan 14, 2026
Bug Fixes

* Fix ``DbtSourceWatcherOperator.template_fields`` to inherit from
``DbtSourceLocalOperator`` instead of ``DbtConsumerWatcherSensor`` by
@pankajkoti in #2226
* Fix TypeError in Watcher mode with subprocess invocation by
@pankajkoti in #2227
* Error when RenderConfig.invocation_mode is incorrectly set by @tatiana
in #2267

Docs

* Fix minor documentation typo by @dnskr in #2093
* Fix default values in documentation by @dnskr in #2092
* Remove emit event for ExecutionMode.AIRFLOW_ASYNC limitation in docs
by @pankajastro in #2214

Others

* Add test to check profile metrics with non-Cosmos operator by
@pankajastro in #2215
* Fix CI main branch Airflow 2.6 tests by @tatiana in #2268

closes:
astronomer/oss-integrations-private#295

Co-authored-by: Tatiana Al-Chueyr <tatiana.alchueyr@gmail.com>
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.

[Bug] Watcher Producer in subprocess mode fails with TypeError: _store_dbt_resource_status_from_log() takes 2 positional arguments but 3 were given

3 participants