You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "yulit0738 (via GitHub)" <gi...@apache.org> on 2026/03/23 05:46:43 UTC
[PR] Fix DagRun._emit_dagrun_span crash on None/empty context_carrier [airflow]
yulit0738 opened a new pull request, #64087:
URL: https://github.com/apache/airflow/pull/64087
## Summary
Fixes a crash in `DagRun._emit_dagrun_span()` when `context_carrier` is `None` or empty `{}`.
- **Symptom**: `AttributeError: 'NoneType' object has no attribute 'get'` in `TraceContextTextMapPropagator().extract()`
- **Cause**: DagRuns created before OTel tracing was enabled have `context_carrier = NULL` in the database. When these DagRuns complete, `_emit_dagrun_span()` passes `None` directly to `extract()`.
- **Fix**: Early return when `context_carrier` is falsy, consistent with the existing guard in `task_runner.py:148`.
## Reproduction Path
1. Have existing DagRuns in the database (created before OTel was enabled → `context_carrier = NULL`)
2. Enable OTel tracing
3. Those DagRuns complete → `update_state()` → `_emit_dagrun_span()` → crash
**Note**: This supersedes #61655 which targeted `OtelTrace.extract()` — that class was since removed in #63452.
## Testing
- Added parametrized unit test covering both `None` and `{}` carrier values
- Verified no span is emitted when carrier is missing (graceful skip)
---
**Was generative AI tooling used to co-author this PR?**
- [X] Yes (please specify the tool below)
Generated-by: Claude (Anthropic) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix DagRun._emit_dagrun_span crash on None/empty context_carrier [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on PR #64087:
URL: https://github.com/apache/airflow/pull/64087#issuecomment-4108184994
`TraceContextTextMapPropagator().extract()` already has logic to deal with None and empty dict. I am under the impression these are expected values that should go through the same code path, not silently excluded early.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix DagRun._emit_dagrun_span crash on None/empty context_carrier [airflow]
Posted by "yulit0738 (via GitHub)" <gi...@apache.org>.
yulit0738 commented on PR #64087:
URL: https://github.com/apache/airflow/pull/64087#issuecomment-4108434343
@uranusjr
Updated — now using `self.context_carrier or {}` instead of the early return, so OTel receives a valid carrier and emits a root span per spec.
You were right that this should go through the same code path. The only issue was `None` specifically — `DefaultGetter.get()` calls `carrier.get(key, None)` which raises `AttributeError` on `None`. The `or {}` lets OTel handle it naturally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix DagRun._emit_dagrun_span crash on None/empty context_carrier [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on PR #64087:
URL: https://github.com/apache/airflow/pull/64087#issuecomment-4108240925
Let’s pass `self.context_carrier or {}` to OTel then, that’s probably more idiomatic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix DagRun._emit_dagrun_span crash on None/empty context_carrier [airflow]
Posted by "yulit0738 (via GitHub)" <gi...@apache.org>.
yulit0738 commented on PR #64087:
URL: https://github.com/apache/airflow/pull/64087#issuecomment-4108230941
> `TraceContextTextMapPropagator().extract()` already has logic to deal with None and empty dict. I am under the impression these are expected values that should go through the same code path, not silently excluded early.
@uranusjr verified against the latest `opentelemetry-python` main — `TraceContextTextMapPropagator.extract()` has no `None` guard for carrier. [`DefaultGetter.get()`](https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-api/src/opentelemetry/propagators/textmap.py#L86) calls
`carrier.get(key, None)` directly, which raises `AttributeError` on `None`.
The `context_carrier` column is [`nullable=True`](https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/models/dagrun.py#L216-L219). After upgrading Airflow to a version with OTel tracing, existing DagRuns in the DB have `context_carrier = NULL`. When those DagRuns complete,
the scheduler crashes in `_emit_dagrun_span()` — not a task failure, but a scheduler process crash.
`task_runner.py:148` already uses the same pattern: `if msg.ti.context_carrier else None`.
I can narrow the guard to only `None` (not empty dict) if you prefer — `{}` does pass through `extract()` safely.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix DagRun._emit_dagrun_span crash on None/empty context_carrier [airflow]
Posted by "vatsrahul1001 (via GitHub)" <gi...@apache.org>.
vatsrahul1001 merged PR #64087:
URL: https://github.com/apache/airflow/pull/64087
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org