Fix TypeError in Watcher mode with subprocess invocation#2227
Conversation
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.
✅ Deploy Preview for astronomer-cosmos canceled.
|
There was a problem hiding this comment.
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_callablewithstaticmethod()to prevent method binding - Added comprehensive test coverage for
_store_dbt_resource_status_from_logfunction - 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
tatiana
left a comment
There was a problem hiding this comment.
Thanks for fixing this, @pankajkoti ! Looks great
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
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>
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