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/13 20:06:39 UTC

[GitHub] [airflow] OmairK commented on a change in pull request #9170: [WIP] Read only endpoint for XCom #8134

OmairK commented on a change in pull request #9170:
URL: https://github.com/apache/airflow/pull/9170#discussion_r439765576



##########
File path: airflow/api_connexion/endpoints/xcom_endpoint.py
##########
@@ -26,18 +31,35 @@ def delete_xcom_entry():
     raise NotImplementedError("Not implemented yet.")
 
 
-def get_xcom_entries():
+@provide_session
+def get_xcom_entries(dag_id, dag_run_id, task_id, session):
     """
     Get all XCom values
     """
-    raise NotImplementedError("Not implemented yet.")
+    query = session.query(XCom)
+    query = query.filter(and_(XCom.dag_id == dag_id,
+                              XCom.task_id == task_id))
+    query = query.join(DR, and_(XCom.dag_id == DR.dag_id, XCom.execution_date == DR.execution_date))
+    query = query.filter(DR.run_id == dag_run_id)
+    return xcom_collection_schema.dump(XComCollection(xcom_entries=query.all(), total_entries=query.count()))
 
 
-def get_xcom_entry():
+@provide_session
+def get_xcom_entry(dag_id, task_id, dag_run_id, xcom_key, session):
     """
     Get an XCom entry
     """
-    raise NotImplementedError("Not implemented yet.")
+    query = session.query(XCom)
+    query = query.filter(and_(XCom.dag_id == dag_id,
+                              XCom.task_id == task_id,
+                              XCom.key == xcom_key))
+    query = query.join(DR, and_(XCom.dag_id == DR.dag_id, XCom.execution_date == DR.execution_date))
+    query = query.filter(DR.run_id == dag_run_id)
+
+    q_object = query.one_or_none()
+    if not q_object:
+        raise Exception("Object Not found")

Review comment:
       API is exceptions are defined in one of the PRs [here](https://github.com/apache/airflow/blob/287932c276dae6bce242051a40cff3680c238626/airflow/api_connexion/exceptions.py#L20). I think it would be better to raise a 404 exception here. @randr97  what do you think ?




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