You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BranchingOperator fails when using custom backend xcom deserialization with NoCredentialsError #50491
I'm encountering an issue when deserializing XComs using a custom XCom backend that loads data from S3 using S3Hook(aws_conn_id='aws'). aws is the connection Id defined with the aws credentials. The same code is working for Airflow 2.10.4 but not anymore from 2.10.5 and further.
Despite having a valid AWS connection configured in Airflow (visible and working well in ALL other parts of the DAG), I get the following error during deserialization steps:
```botocore.exceptions.NoCredentialsError: Unable to locate credentials````
This error is not visible in the Airflow UI but I found it in the scheduler container's logs. The branching task is set as success but the following branched task is queued 'forever'. I assume this error is coming from the following task which is pulling a xcom.
After switching to manual session initialization using boto3.Session(...), I still have the same error... BUT it is working and I am settings the aws credentials directly inside the code, without trying to get the aws Connection Id. This is telling me that in the specific case of BranchingOperator, something is happening and the follwing task' context doesn't have the connection Id anymore.
What you think should happen instead?
The 'aws' connection is not resolved correctly anymore by the scheduler, even though it is defined in Airflow. The context might have changed?
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
[UPDATE]
I think I found the solution for my error (BUT I still don't understand why the behavior has changed after v2.10.4):
Airflow uses xcom_pull() in its internal dependency rules to determine if a task was previously "skipped" due to a branch.
This is part of the mechanism that prevents downstream tasks of a BranchPythonOperator from being executed if they were skipped by the branch.
This explains why the deserialization of the branch XCom occurs before the next branch task is even scheduled or executed.
In other words: The scheduler reads the XCom generated by the branching task to determine whether the current task should be skipped, set to None, or scheduled.
As the deserialization of the XCom only depends on access to the data and the result stored in the Airflow database, if the XCom is properly stored and its value (even if it’s an S3 link) is present in the database, it will not prevent the scheduler or worker from understanding the task’s state and making the correct decisions.
So in the deserialize_value() function, I need to add an early exit to skip full deserialization if it running outside task context (eg: Scheduler after BranchingOperator). This is made by checking one of the Airflow env variable given in a 'real' task context:
# Early exit: skip full deserialization if running outside task context (Scheduler after BranchingOperator)
if not bool(os.environ.get("AIRFLOW_CTX_DAG_ID")):
# Return the raw pointer (ex: xcom_s3://...) for comparison or logging
task_logger.warning("XCom deserialization attempted outside task context (probably in the scheduler), skipping download and deserialize: %s", result)
return result
Activity
boring-cyborg commentedon May 12, 2025
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
NicolasBearingPoint commentedon May 12, 2025
[UPDATE]
I think I found the solution for my error (BUT I still don't understand why the behavior has changed after v2.10.4):
So in the
deserialize_value()function, I need to add an early exit to skip full deserialization if it running outside task context (eg: Scheduler after BranchingOperator). This is made by checking one of the Airflow env variable given in a 'real' task context:Can someone approve this ? Thanks!
docs: note custom XCom deserialize_value may run in scheduler context (…
docs: clarify scheduler-safe custom XCom guidance (apache#50491)
eladkal commentedon May 20, 2026
@Subham-KRLX do you think maybe you can check this issue?
Subham-KRLX commentedon May 20, 2026
I am currently busy with other pull requests but I will definitely look into this issue as soon as I have a moment.
darshil929 commentedon Jun 21, 2026
I'll work on this.
Add newsfragment for apache#50491
Fix branch not skipping mapped tasks with custom XCom backend (#68954)