o-nikolas commented on code in PR #75521:
URL: https://github.com/apache/airflow/pull/75521#discussion_r4646734628


##########
airflow-core/docs/core-concepts/asset-state-store.rst:
##########
@@ -234,6 +241,15 @@ The corresponding 
:class:`~airflow.sdk.definitions.asset.AssetWatcher` wires the
 
     ...
 
+Two assets watched by the same trigger share it, and its state is written to 
both:
+
+.. code-block:: python
+
+    orders_trigger = PollEventsTrigger(source="orders", waiter_delay=30)
+
+    orders_eu = Asset(name="orders_eu", 
watchers=[AssetWatcher(name="eu_watcher", trigger=orders_trigger)])
+    orders_us = Asset(name="orders_us", 
watchers=[AssetWatcher(name="us_watcher", trigger=orders_trigger)])
+
 ``self.asset_state_store`` behaves identically to the per-asset accessor 
described in the task sections above: ``get``, ``set``, ``delete``, ``clear`` 
and their async counterparts ``aget``, ``aset``, ``adelete``, ``aclear`` are 
all available. Values written by the trigger are visible to any task that 
declares ``my_asset`` as an inlet or outlet, and vice versa.

Review Comment:
   nit: this sentence isn't quite true any more for a shared trigger, since 
`get`/`set`/`delete` now behave differently and a task that writes to 
`orders_us` won't be seen if `orders_eu` holds the key. Maybe start it with 
"For a trigger that watches one asset, ..." and point at the paragraph above 
for the shared case?



##########
task-sdk/src/airflow/sdk/execution_time/context.py:
##########
@@ -1227,6 +1227,57 @@ def __repr__(self) -> str:
         return f"<AssetStateStoreAccessors [{', '.join(parts)}]>"
 
 
+class TriggerAssetStateStoreAccessors(AssetStateStoreAccessors):
+    """
+    Asset state store accessors the triggerer gives a watcher trigger.
+
+    A trigger shared by several assets keeps one value for all of them: 
``set`` and ``delete``
+    write to every asset, and ``get`` returns the value from the first asset 
(by name) that has
+    the key. ``clear`` still needs exactly one asset, so it can't remove keys 
that tasks wrote.

Review Comment:
   nit: when a shared trigger does call `clear()`, it gets the task error, 
"Task has 2 concrete inlets and outlets — use 
context['asset_state_store'][MY_ASSET] to specify which", which points a 
trigger author at a `context` they don't have. Could this class override 
`_single_accessor` (or `clear`/`aclear`) with a trigger-specific message, e.g. 
"clear() needs exactly one watched asset; use delete() for this trigger's keys"?



-- 
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]

Reply via email to