ashb commented on code in PR #45727:
URL: https://github.com/apache/airflow/pull/45727#discussion_r1920085635


##########
task_sdk/src/airflow/sdk/execution_time/context.py:
##########
@@ -163,6 +174,114 @@ def __eq__(self, other: object) -> bool:
         return True
 
 
[email protected]
+class AssetAliasEvent:
+    """Representation of asset event to be triggered by an asset alias."""
+
+    source_alias_name: str
+    dest_asset_key: AssetUniqueKey
+    extra: dict[str, Any]
+
+
[email protected]
+class OutletEventAccessor:
+    """Wrapper to access an outlet asset event in template."""
+
+    key: BaseAssetUniqueKey
+    extra: dict[str, Any] = attrs.Factory(dict)
+    asset_alias_events: list[AssetAliasEvent] = attrs.field(factory=list)
+
+    def add(self, asset: Asset, extra: dict[str, Any] | None = None) -> None:
+        """Add an AssetEvent to an existing Asset."""
+        if not isinstance(self.key, AssetAliasUniqueKey):
+            return
+
+        asset_alias_name = self.key.name
+        event = AssetAliasEvent(
+            source_alias_name=asset_alias_name,
+            dest_asset_key=AssetUniqueKey.from_asset(asset),
+            extra=extra or {},
+        )
+        self.asset_alias_events.append(event)
+
+
+def _get_asset(name: str | None = None, uri: str | None = None) -> Asset:
+    from airflow.sdk.definitions.asset import Asset
+    from airflow.sdk.execution_time.comms import ErrorResponse, 
GetAssetByName, GetAssetByUri
+    from airflow.sdk.execution_time.task_runner import SUPERVISOR_COMMS
+
+    if name:
+        SUPERVISOR_COMMS.send_request(log=log, msg=GetAssetByName(name=name))
+    elif uri:
+        SUPERVISOR_COMMS.send_request(log=log, msg=GetAssetByUri(uri=uri))
+    else:
+        raise ValueError("Either name or uri must be provided")
+
+    msg = SUPERVISOR_COMMS.get_message()
+    if isinstance(msg, ErrorResponse):
+        raise AirflowRuntimeError(msg)
+
+    if TYPE_CHECKING:
+        assert isinstance(msg, AssetResult)
+    return Asset(**msg.model_dump(exclude={"type"}))
+
+
+class OutletEventAccessors(Mapping[Union[Asset, AssetAlias], 
OutletEventAccessor]):

Review Comment:
   I'm not too familiar with this context key, but aren'te Outlets defined on 
the task, i.e. we shouldn't need to go to the server for this?



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