pierrejeambrun commented on code in PR #43508:
URL: https://github.com/apache/airflow/pull/43508#discussion_r1829717172
##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -121,23 +124,34 @@ async def patch_dag_run_state(
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Dag with id {dag_id}
was not found")
if update_mask:
- if update_mask != ["state"]:
- raise HTTPException(
- status.HTTP_400_BAD_REQUEST, "Only `state` field can be
updated through the REST API"
- )
+ for each in update_mask:
+ if each not in ALLOWED_FIELD_MASK:
+ raise HTTPException(400, f"Invalid field `{each}` in update
mask")
else:
- update_mask = ["state"]
+ update_mask = ALLOWED_FIELD_MASK
- for attr_name in update_mask:
- if attr_name == "state":
- state = getattr(patch_body, attr_name)
- if state == DAGRunPatchStates.SUCCESS:
- set_dag_run_state_to_success(dag=dag, run_id=dag_run.run_id,
commit=True)
- elif state == DAGRunPatchStates.QUEUED:
- set_dag_run_state_to_queued(dag=dag, run_id=dag_run.run_id,
commit=True)
- else:
- set_dag_run_state_to_failed(dag=dag, run_id=dag_run.run_id,
commit=True)
+ if "state" in update_mask:
+ attr_value = getattr(patch_body, "state")
+ if attr_value == DAGRunPatchStates.SUCCESS:
+ set_dag_run_state_to_success(dag=dag, run_id=dag_run.run_id,
commit=True, session=session)
+ elif attr_value == DAGRunPatchStates.QUEUED:
+ set_dag_run_state_to_queued(dag=dag, run_id=dag_run.run_id,
commit=True, session=session)
+ elif attr_value == DAGRunPatchStates.FAILED:
+ set_dag_run_state_to_failed(dag=dag, run_id=dag_run.run_id,
commit=True, session=session)
dag_run = session.get(DagRun, dag_run.id)
+ for attr_name in update_mask:
+ attr_value = getattr(patch_body, attr_name)
+ if attr_value is None:
+ continue
Review Comment:
In case the `update_mask` is explicitely provided by the user, we shouldn't
avoid `None` values.
If someone gives `{"note": None}` to reset the note, he it should work, and
not get ignored. (same for other fields, you can check other `PATH` endpoint to
get more information on how to do that).
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]