You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/06/30 00:00:53 UTC

[GitHub] [airflow] kaxil opened a new pull request #9580: Add XCom.get_one() method back

kaxil opened a new pull request #9580:
URL: https://github.com/apache/airflow/pull/9580


   It is a handy function to handle and many times we just need a single Xcom value and `Xcom.get_one()` can be a good candidate for that.
   
   ---
   Make sure to mark the boxes below before creating PR: [x]
   
   - [x] Description above provides context of the change
   - [x] Unit tests coverage for changes (not needed for documentation changes)
   - [x] Target Github ISSUE in description if exists
   - [x] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [x] Relevant documentation is updated including usage instructions.
   - [x] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil merged pull request #9580: Add XCom.get_one() method back

Posted by GitBox <gi...@apache.org>.
kaxil merged pull request #9580:
URL: https://github.com/apache/airflow/pull/9580


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #9580: Add XCom.get_one() method back

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #9580:
URL: https://github.com/apache/airflow/pull/9580#discussion_r447339664



##########
File path: airflow/models/xcom.py
##########
@@ -118,6 +118,45 @@ def set(
 
         session.commit()
 
+    @classmethod
+    @provide_session
+    def get_one(cls,
+                execution_date: pendulum.DateTime,
+                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):
+        """
+        Retrieve an XCom value, optionally meeting certain criteria.
+
+        :param execution_date: Execution date for the task
+        :type execution_date: pendulum.datetime
+        :param key: A key for the XCom. If provided, only XComs with matching
+            keys will be returned. To remove the filter, pass key=None.
+        :type key: str
+        :param task_id: Only XComs from task with matching id will be
+            pulled. Can pass None to remove the filter.
+        :type task_id: str
+        :param dag_id: If provided, only pulls XCom from this DAG.
+            If None (default), the DAG of the calling task is used.
+        :type dag_id: str
+        :param include_prior_dates: If False, only XCom from the current
+            execution_date are returned. If True, XCom from previous dates
+            are returned as well.
+        :type include_prior_dates: bool
+        :param session: database session
+        :type session: sqlalchemy.orm.session.Session
+        """
+        result = cls.get_many(execution_date=execution_date,
+                              key=key,
+                              task_ids=task_id,
+                              dag_ids=dag_id,
+                              include_prior_dates=include_prior_dates,
+                              session=session).first()
+        if result:
+            return result.value
+

Review comment:
       Updated in https://github.com/apache/airflow/pull/9580/commits/4ac2d0931fa646bb7bb7d6e4a4104b4a053796ac




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on a change in pull request #9580: Add XCom.get_one() method back

Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #9580:
URL: https://github.com/apache/airflow/pull/9580#discussion_r447338202



##########
File path: airflow/models/xcom.py
##########
@@ -118,6 +118,45 @@ def set(
 
         session.commit()
 
+    @classmethod
+    @provide_session
+    def get_one(cls,
+                execution_date: pendulum.DateTime,
+                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):
+        """
+        Retrieve an XCom value, optionally meeting certain criteria.
+
+        :param execution_date: Execution date for the task
+        :type execution_date: pendulum.datetime
+        :param key: A key for the XCom. If provided, only XComs with matching
+            keys will be returned. To remove the filter, pass key=None.
+        :type key: str
+        :param task_id: Only XComs from task with matching id will be
+            pulled. Can pass None to remove the filter.
+        :type task_id: str
+        :param dag_id: If provided, only pulls XCom from this DAG.
+            If None (default), the DAG of the calling task is used.
+        :type dag_id: str
+        :param include_prior_dates: If False, only XCom from the current
+            execution_date are returned. If True, XCom from previous dates
+            are returned as well.
+        :type include_prior_dates: bool
+        :param session: database session
+        :type session: sqlalchemy.orm.session.Session
+        """
+        result = cls.get_many(execution_date=execution_date,
+                              key=key,
+                              task_ids=task_id,
+                              dag_ids=dag_id,
+                              include_prior_dates=include_prior_dates,
+                              session=session).first()
+        if result:
+            return result.value
+

Review comment:
       For the 'explicitness' - I think we should explicitly return None here and have Optional return + return type here. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #9580: Add XCom.get_one() method back

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #9580:
URL: https://github.com/apache/airflow/pull/9580#discussion_r447338484



##########
File path: airflow/models/xcom.py
##########
@@ -118,6 +118,45 @@ def set(
 
         session.commit()
 
+    @classmethod
+    @provide_session
+    def get_one(cls,
+                execution_date: pendulum.DateTime,
+                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):
+        """
+        Retrieve an XCom value, optionally meeting certain criteria.
+
+        :param execution_date: Execution date for the task
+        :type execution_date: pendulum.datetime
+        :param key: A key for the XCom. If provided, only XComs with matching
+            keys will be returned. To remove the filter, pass key=None.
+        :type key: str
+        :param task_id: Only XComs from task with matching id will be
+            pulled. Can pass None to remove the filter.
+        :type task_id: str
+        :param dag_id: If provided, only pulls XCom from this DAG.
+            If None (default), the DAG of the calling task is used.
+        :type dag_id: str
+        :param include_prior_dates: If False, only XCom from the current
+            execution_date are returned. If True, XCom from previous dates
+            are returned as well.
+        :type include_prior_dates: bool
+        :param session: database session
+        :type session: sqlalchemy.orm.session.Session
+        """
+        result = cls.get_many(execution_date=execution_date,
+                              key=key,
+                              task_ids=task_id,
+                              dag_ids=dag_id,
+                              include_prior_dates=include_prior_dates,
+                              session=session).first()
+        if result:
+            return result.value
+

Review comment:
       Agree




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on a change in pull request #9580: Add XCom.get_one() method back

Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #9580:
URL: https://github.com/apache/airflow/pull/9580#discussion_r447338202



##########
File path: airflow/models/xcom.py
##########
@@ -118,6 +118,45 @@ def set(
 
         session.commit()
 
+    @classmethod
+    @provide_session
+    def get_one(cls,
+                execution_date: pendulum.DateTime,
+                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):
+        """
+        Retrieve an XCom value, optionally meeting certain criteria.
+
+        :param execution_date: Execution date for the task
+        :type execution_date: pendulum.datetime
+        :param key: A key for the XCom. If provided, only XComs with matching
+            keys will be returned. To remove the filter, pass key=None.
+        :type key: str
+        :param task_id: Only XComs from task with matching id will be
+            pulled. Can pass None to remove the filter.
+        :type task_id: str
+        :param dag_id: If provided, only pulls XCom from this DAG.
+            If None (default), the DAG of the calling task is used.
+        :type dag_id: str
+        :param include_prior_dates: If False, only XCom from the current
+            execution_date are returned. If True, XCom from previous dates
+            are returned as well.
+        :type include_prior_dates: bool
+        :param session: database session
+        :type session: sqlalchemy.orm.session.Session
+        """
+        result = cls.get_many(execution_date=execution_date,
+                              key=key,
+                              task_ids=task_id,
+                              dag_ids=dag_id,
+                              include_prior_dates=include_prior_dates,
+                              session=session).first()
+        if result:
+            return result.value
+

Review comment:
       For the 'explicitness' - I think we should explicitly return None here and have Optional return + return type in the docs explaining when None is returned.. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org