jroachgolf84 commented on code in PR #75521: URL: https://github.com/apache/airflow/pull/75521#discussion_r4681096526
########## airflow-core/docs/core-concepts/asset-state-store.rst: ########## @@ -168,9 +168,15 @@ Calling the synchronous ``get``/``set``/``delete``/``clear`` from inside an ``as Using ``asset_state_store`` inside a Watcher Trigger ----------------------------------------------------- -:class:`~airflow.triggers.base.BaseEventTrigger` subclasses (watcher triggers) can read and write asset state store directly from within ``run()``. The triggerer injects ``self.asset_state_store`` before ``run()`` is called, scoped to the asset the trigger is watching. It is not available during ``__init__`` or ``serialize()``, only access it from within ``run()``. +:class:`~airflow.triggers.base.BaseEventTrigger` subclasses (watcher triggers) can read and write asset state store directly from within ``run()``. The triggerer injects ``self.asset_state_store`` before ``run()`` is called, scoped to the asset or assets this trigger watches. It is not available during ``__init__`` or ``serialize()``, only access it from within ``run()``. -Unlike task-based access (where the asset is identified by an inlet or outlet declaration), the accessor in a watcher trigger is automatically bound to the watched asset, so no subscripting is needed. +Unlike task-based access (where the asset is identified by an inlet or outlet declaration), the accessor in a watcher trigger is automatically bound to the watched assets, so no subscripting is needed. + +Watchers on several assets that use the same trigger class and arguments share one trigger. The accessor then covers all of those assets: ``set`` and ``delete`` apply to every one of them, and ``get`` returns the value from the first asset (by name) that holds the key. ``clear`` still needs exactly one asset, because it would also remove keys that tasks wrote, so a shared trigger should ``delete`` its own keys instead. Tasks and other triggers can use the same assets, so include what the trigger watches in the key name. Review Comment: Real quick, on this. What about this scenario? * Trigger X is watching Assets 1, 2, and 3. * From the Trigger, `set` is used to update the `watermark` to `2026-02-24` * The next read, `get` returns the value for Asset 1, which is `2026-02-24` * `set` is used to update the `watermark` to `2026-02-25` * However, there is a Task that updates Asset 1 to have a `watermark` of `2026-12-31` * Now, the next `get` is reading the Asset 1 value, which was updated outside of the Trigger, and is applied to the other Assets Thoughts on this? Is is fair to make the assumption that the Assets being watched by a Trigger should basically be treated as "the same thing" (even if there are multiple). -- 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]
