Skip to content

Commit 707096f

Browse files
pankajastroclaude
andcommitted
Guard store_dbt_resource_status_from_log against falsy extra_kwargs
The refactor dropped the original `if extra_kwargs` guard, leaving several unconditional `extra_kwargs.get(...)` calls that would raise AttributeError if extra_kwargs were None/non-mapping. Normalise `extra_kwargs = extra_kwargs or {}` at the top so all accesses are safe, restoring the original falsy-handling. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5fb9bed commit 707096f

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

cosmos/operators/_watcher/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ def store_dbt_resource_status_from_log(
469469
terminal state and may be re-flushed if a later error event provides the message (e.g. subprocess mode).
470470
This replaces the previous per-event XCom push, which wrote on every event (lock contention) and let a trailing ``NodeFinished`` overwrite the captured error message.
471471
"""
472+
# extra_kwargs is typed Any and may be falsy/None; normalise so the .get() calls below are safe.
473+
extra_kwargs = extra_kwargs or {}
472474
try:
473475
log_line = json.loads(line)
474476
except json.JSONDecodeError:

tests/operators/_watcher/test_watcher_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
_flush_dbt_event,
1010
_flush_dbt_event_on_error,
1111
_process_dbt_log_event,
12+
store_dbt_resource_status_from_log,
1213
)
1314
from cosmos.operators.local import DbtRunLocalOperator
1415

@@ -351,6 +352,13 @@ def test_none_string_status_is_ignored(self):
351352
_accumulate_dbt_log_event(buffer, self._run_result_error(msg="err")) # node_status == "None"
352353
assert buffer[self.UID]["status"] is None
353354

355+
@pytest.mark.parametrize("extra_kwargs", [None, {}])
356+
def test_store_dbt_resource_status_from_log_tolerates_falsy_extra_kwargs(self, extra_kwargs):
357+
"""A falsy/None extra_kwargs must not raise during parsing (no context to push to)."""
358+
line = '{"info": {"name": "NodeFinished"}, "data": {"node_info": {"unique_id": "model.p.m", "node_status": "success"}}}'
359+
# Should be a no-op (no context/ti) rather than raising AttributeError.
360+
store_dbt_resource_status_from_log(line, extra_kwargs, node_event_buffer={})
361+
354362
def test_accumulate_ignores_non_allowlisted_and_missing_unique_id(self):
355363
buffer: dict = {}
356364
_accumulate_dbt_log_event(

0 commit comments

Comments
 (0)