RyukR1 commented on code in PR #77465:
URL: https://github.com/apache/airflow/pull/77465#discussion_r4737653621
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py:
##########
@@ -964,3 +966,52 @@ def delete_dag_asset_queued_event(
f"Queued event with dag_id: `{dag_id}` and asset_id:
`{asset_id}`", partition_key
),
)
+
+
+@assets_router.patch(
+ "/assets/{asset_id}/watchers/{watcher_name}",
Review Comment:
Good catch! Switched the endpoint to `PATCH
/api/v2/assets/{asset_id}/watchers/{trigger_id}`.
Because `AssetWatcherModel`'s primary key is `(asset_id, trigger_id)` and
watcher names are neither constrained to be unique nor guaranteed to be
URL-safe, taking `trigger_id` directly targets the primary key. This cleanly
resolves the 405 on slash names like `team/slash_w` and prevents ambiguity when
multiple watchers share a name.
I've updated the FastAPI route, OpenAPI definitions, the UI
queries/components (`TogglePauseWatcher`), and added a test verifying that
duplicate-named and slash-named watchers are paused and unpaused independently
by `trigger_id`.
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py:
##########
@@ -964,3 +966,52 @@ def delete_dag_asset_queued_event(
f"Queued event with dag_id: `{dag_id}` and asset_id:
`{asset_id}`", partition_key
),
)
+
+
+@assets_router.patch(
+ "/assets/{asset_id}/watchers/{watcher_name}",
+ responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+ dependencies=[
+ Depends(requires_access_asset(method="PUT")),
+ Depends(action_logging()),
+ ],
+)
+def patch_asset_watcher(
+ asset_id: int,
+ watcher_name: str,
+ patch_body: AssetWatcherPatchBody,
+ session: SessionDep,
+) -> AssetWatcherResponse:
+ """Pause or resume an asset watcher."""
+ watcher = session.scalar(
+ select(AssetWatcherModel)
+ .where(
+ AssetWatcherModel.asset_id == asset_id,
+ AssetWatcherModel.name == watcher_name,
+ )
+ .options(joinedload(AssetWatcherModel.trigger))
+ )
+ if watcher is None:
+ raise HTTPException(
+ status.HTTP_404_NOT_FOUND,
+ f"Asset watcher with asset_id: {asset_id} and name:
'{watcher_name}' was not found",
+ )
+
+ watcher.is_paused = patch_body.is_paused
+
+ if patch_body.is_paused and watcher.trigger is not None:
+ all_watchers = session.scalars(
+ select(AssetWatcherModel).where(AssetWatcherModel.trigger_id ==
watcher.trigger_id)
+ ).all()
+ if all(w.is_paused for w in all_watchers):
+ watcher.trigger.triggerer_id = None
Review Comment:
Updated! In `TriggerRunnerSupervisor.update_triggers`, we now partition
`assignments` into `reassigned` (where `owner is not None`) and `unassigned`
(where `owner is None`).
When all watchers for a trigger are paused and `triggerer_id` is cleared to
`None`, the supervisor now explicitly logs:
`"Triggers were paused or unassigned, releasing them without on_kill",
triggers=[...]`
instead of reporting `new_owners={...: None}`.
The trigger is still dropped cleanly without invoking `on_kill()` (avoiding
remote cancellation while paused), and added a unit test
`test_update_triggers_distinguishes_pause_from_reassignment_log` to verify this
distinction.
--
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]