Skip to content

Disallow using an empty key in XCom pull #46925

@vatsrahul1001

Description

@vatsrahul1001

Body

Currently we allow this pulled_value_1 = ti.xcom_pull(key="", task_ids="push"). We should not allow sending empty keys

pulled_value_1 = ti.xcom_pull(key=None, task_ids="push")

Eventually leads to:

    @staticmethod
    @provide_session
    def get_many(
        *,
        run_id: str,
        key: str | None = None,
        task_ids: str | Iterable[str] | None = None,
        dag_ids: str | Iterable[str] | None = None,
        map_indexes: int | Iterable[int] | None = None,
        include_prior_dates: bool = False,
        limit: int | None = None,
        session: Session = NEW_SESSION,
    ) -> Query:
        """
        Composes a query to get one or more XCom entries.

        This function returns an SQLAlchemy query of full XCom objects. If you
        just want one stored value, use :meth:`get_one` instead.

        :param run_id: DAG run ID for the task.
        :param key: A key for the XComs. If provided, only XComs with matching
            keys will be returned. Pass *None* (default) to remove the filter.

Here we see that a non empty value for "key" disables the filter (no where(XCom.key == key), it does not filter for None.

This is how it looks:

if key:
    query = query.filter(BaseXCom.key == key)

It really doesn't make any sense to have an xcom with "" as key.

Committer

  • I acknowledge that I am a maintainer/committer of the Apache Airflow project.

Metadata

Metadata

Assignees

Labels

affected_version:3.0Issues Reported for 3.0area:coregood first issuekind:metaHigh-level information important to the communitypriority:mediumBug that should be fixed before next release but would not block a release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions