airflow.models.xcom
¶
Module Contents¶
-
class
airflow.models.xcom.
BaseXCom
[source]¶ Bases:
airflow.models.base.Base
,airflow.utils.log.logging_mixin.LoggingMixin
Base class for XCom objects.
-
init_on_load
(self)[source]¶ Called by the ORM after the instance has been loaded from the DB or otherwise reconstituted i.e automatically deserialize Xcom value when loading from DB.
-
classmethod
set
(cls, key, value, task_id, dag_id, execution_date=None, run_id=None, session=None)[source]¶ Store an XCom value.
- Returns
None
-
classmethod
get_one
(cls, execution_date: Optional[pendulum.DateTime] = None, run_id: Optional[str] = None, key: Optional[str] = None, task_id: Optional[Union[str, Iterable[str]]] = None, dag_id: Optional[Union[str, Iterable[str]]] = None, include_prior_dates: bool = False, session: Session = None)[source]¶ Retrieve an XCom value, optionally meeting certain criteria. Returns None of there are no results.
run_id
andexecution_date
are mutually exclusive.This method returns "full" XCom values (i.e. it uses
deserialize_value
from the XCom backend). Please useget_many()
if you want the "shortened" value viaorm_deserialize_value
- Parameters
execution_date (pendulum.datetime) -- Execution date for the task
run_id (str) -- Dag run id for the task
key (str) -- A key for the XCom. If provided, only XComs with matching keys will be returned. To remove the filter, pass key=None.
task_id (str) -- Only XComs from task with matching id will be pulled. Can pass None to remove the filter.
dag_id (str) -- If provided, only pulls XCom from this DAG. If None (default), the DAG of the calling task is used.
include_prior_dates (bool) -- If False, only XCom from the current execution_date are returned. If True, XCom from previous dates are returned as well.
session (sqlalchemy.orm.session.Session) -- database session
-
classmethod
get_many
(cls, execution_date: Optional[pendulum.DateTime] = None, run_id: Optional[str] = None, key: Optional[str] = None, task_ids: Optional[Union[str, Iterable[str]]] = None, dag_ids: Optional[Union[str, Iterable[str]]] = None, include_prior_dates: bool = False, limit: Optional[int] = None, session: Session = None)[source]¶ Composes a query to get one or more values from the xcom table.
run_id
andexecution_date
are mutually exclusive.This function returns an SQLAlchemy query of full XCom objects. If you just want one stored value then use
get_one()
.- Parameters
execution_date (pendulum.datetime) -- Execution date for the task
run_id (str) -- Dag run id for the task
key (str) -- A key for the XCom. If provided, only XComs with matching keys will be returned. To remove the filter, pass key=None.
task_ids (str or iterable of strings (representing task_ids)) -- Only XComs from tasks with matching ids will be pulled. Can pass None to remove the filter.
dag_ids (str) -- If provided, only pulls XComs from this DAG. If None (default), the DAG of the calling task is used.
include_prior_dates (bool) -- If False, only XComs from the current execution_date are returned. If True, XComs from previous dates are returned as well.
limit (int) -- If required, limit the number of returned objects. XCom objects can be quite big and you might want to limit the number of rows.
session (sqlalchemy.orm.session.Session) -- database session
-
classmethod
clear
(cls, execution_date: Optional[pendulum.DateTime] = None, dag_id: str = None, task_id: str = None, run_id: str = None, session: Session = None)[source]¶ Clears all XCom data from the database for the task instance
run_id
andexecution_date
are mutually exclusive.- Parameters
execution_date (pendulum.datetime or None) -- Execution date for the task
dag_id (str) -- ID of DAG to clear the XCom for.
task_id (str) -- Only XComs from task with matching id will be cleared.
session (sqlalchemy.orm.session.Session) -- database session
-
orm_deserialize_value
(self)[source]¶ Deserialize method which is used to reconstruct ORM XCom object.
This method should be overridden in custom XCom backends to avoid unnecessary request or other resource consuming operations when creating XCom orm model. This is used when viewing XCom listing in the webserver, for example.
-