When we want to get an XCom variable in the on_failure_callback, we will face a nasty bug. Using the ti
key to retrieve a value from the context gives us a None value.
# This does not work
context.get("ti").xcom_pull(key="test")
It happens because in the on_failure_callback the task instance is passed to the function using the task_instance
key. Therefore to get a value from XCom, we must execute this code:
task: TaskInstance = context.get('task_instance')
task.xcom_pull(key="test")
Alternatively, we can import XCom and access it directly:
from airflow.models import XCom
XCom.get_one(execution_date = context.get('execution_date'), key='test')
Get $80/Year of AI Expertise. For Free.
"I've learned a lot already from your blog."
— A Substack reader who has pledged $80 per year for this content.
I help SaaS startups with customer-facing LLMs stop AI hallucinations before they spark compliance nightmares or customer churn.
Why join?
- Straight-to-the-point articles on measuring and fixing hallucinations.
- Playbooks for advanced RAG tuning, guardrails, and evaluation you can copy-paste.
- Case studies from real deployments, not "Hello World" demos.
What to expect:
- 3-4 actionable emails per month.
- Proven expertise: 500+ articles & 1k+ engineers trained.
- Zero fluff, zero spam — just tactics that make your LLM stack safer.
Subscribe