seanghaeli commented on code in PR #77465:
URL: https://github.com/apache/airflow/pull/77465#discussion_r4676048809
##########
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:
Watcher rows are keyed by asset and trigger, and the name isn't checked to
be unique or URL-safe. A watcher named `team/slash_w` can't be paused (`PATCH
/assets/6/watchers/team%2Fslash_w` gives 405), and on an asset with two
watchers both named `dup_w` this paused one and the other kept firing. Could
the path take the trigger id instead?
##########
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:
The triggerer reads this as a handoff: every pause logs `Triggers were
reassigned to another triggerer, releasing them without on_kill` with
`new_owners={1: None}`. Worth telling a pause apart from a reassignment there,
so nobody goes looking for the other triggerer.
--
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]