Skip to content

BranchingOperator fails when using custom backend xcom deserialization with NoCredentialsError #50491

Closed

Description

@NicolasBearingPoint

Apache Airflow version

2.10.5

If "Other Airflow 2 version" selected, which one?

No response

What happened?

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````

With the function:

hook = S3Hook(aws_conn_id='aws')
head_object = hook.head_object(key=key, bucket_name='bucket')

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?

How to reproduce

class CustomXComBackendPandas(BaseXCom):
    XCOM_PREFIX = "xcom_s3://"
    S3_PATH_PREFIX = "tmp"
    _BUCKET_NAME = ""
    DATAFRAME_EXTENSION = ".parquet"

@staticmethod
    def deserialize_value(result: BaseXCom) -> Any:
            hook = S3Hook(aws_conn_id='aws')
            head_object = hook.head_object(key='key', bucket_name='bucket')

Operating System

macOS 15.4.1 (Sonoma)

Versions of Apache Airflow Providers

No response

Deployment

Astronomer

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on May 12, 2025
  2. boring-cyborg commented on May 12, 2025

    @boring-cyborg

    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.

  3. NicolasBearingPoint commented on May 12, 2025

    @NicolasBearingPoint
    Author

    [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
    

    Can someone approve this ? Thanks!

  4. added and removed
    needs-triage
    on Mar 13, 2026
  5. eladkal commented on May 20, 2026

    @eladkal
    Contributor

    @Subham-KRLX do you think maybe you can check this issue?

  6. Subham-KRLX commented on May 20, 2026

    @Subham-KRLX
    Contributor

    @Subham-KRLX do you think maybe you can check this issue?

    I am currently busy with other pull requests but I will definitely look into this issue as soon as I have a moment.

  7. darshil929 commented on Jun 21, 2026

    @darshil929
    Contributor

    I'll work on this.

  8. modified the milestone: Airflow 3.3.3 on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions