ephraimbuddy commented on a change in pull request #9482:
URL: https://github.com/apache/airflow/pull/9482#discussion_r445524042
##########
File path: airflow/api_connexion/endpoints/xcom_endpoint.py
##########
@@ -14,25 +14,47 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from flask import request
+from typing import List, Optional
+
+from flask import Response, request
+from marshmallow import ValidationError
from sqlalchemy import and_, func
from sqlalchemy.orm.session import Session
from airflow.api_connexion import parameters
-from airflow.api_connexion.exceptions import NotFound
+from airflow.api_connexion.exceptions import BadRequest, NotFound
from airflow.api_connexion.schemas.xcom_schema import (
XComCollection, XComCollectionItemSchema, XComCollectionSchema,
xcom_collection_item_schema,
- xcom_collection_schema,
+ xcom_collection_schema, xcom_schema,
)
from airflow.models import DagRun as DR, XCom
from airflow.utils.session import provide_session
-def delete_xcom_entry():
+@provide_session
+def delete_xcom_entry(
+ dag_id: str,
+ dag_run_id: str,
+ task_id: str,
+ xcom_key: str,
+ session: Session
+) -> Response:
"""
Delete an XCom entry
"""
- raise NotImplementedError("Not implemented yet.")
+
+ dag_run = session.query(DR).filter(DR.run_id == dag_run_id,
+ DR.dag_id == dag_id).first()
+ if not dag_run:
+ raise NotFound(f'DAGRun with dag_id:{dag_id} and run_id:{dag_run_id}
not found')
+
+ entry = session.query(XCom).filter(XCom.dag_id == dag_id,
+ XCom.task_id == task_id,
+ XCom.key == xcom_key).delete()
+ if not entry:
Review comment:
Yeah. The suggestion is good especially when the query is not long.
Here, the query is long and according to the Zen of python, Readability counts,
that's why I assigned the number of rows deleted to entry and check it in the
next line.
----------------------------------------------------------------
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:
[email protected]