pierrejeambrun commented on code in PR #43508:
URL: https://github.com/apache/airflow/pull/43508#discussion_r1829719034
##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -90,21 +93,33 @@ async def patch_dag_run_state(
raise HTTPException(404, f"Dag with id {dag_id} was not found")
if update_mask:
- if update_mask != ["state"]:
- raise HTTPException(400, "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:
+ attr_value = getattr(patch_body, attr_name)
if attr_name == "state":
- state = getattr(patch_body, attr_name)
- if state == DAGRunPatchStates.SUCCESS:
+ if attr_value is None:
+ raise HTTPException(400, "state cannot be empty when it is
included in the update mask")
+ if attr_value == DAGRunPatchStates.SUCCESS:
set_dag_run_state_to_success(dag=dag, run_id=dag_run.run_id,
commit=True)
- elif state == DAGRunPatchStates.QUEUED:
+ elif attr_value == 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)
-
+ elif attr_name == "note":
+ # Once Authentication is implemented in this FastAPI app,
+ # user id will be added when updating dag run note
+ # Refer to https://github.com/apache/airflow/issues/43534
+ if dag_run.dag_run_note is None:
+ dag_run.note = (attr_value, None)
+ else:
+ dag_run.dag_run_note.content = attr_value
Review Comment:
Check the comment below, this is due to sessions and not operating on the
same object for the two updates (states + note, references are actually
different and not operating on the same object).
Normally if we have 1 unique session we could just `refresh` and it should
work.
--
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]