You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by we...@apache.org on 2025/06/27 09:11:46 UTC
(airflow) branch v3-0-test updated: [v3-0-test] fix: task-sdk AssetEventOperations.get to use alias_name when specified (#52303) (#52324)
This is an automated email from the ASF dual-hosted git repository.
weilee pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-0-test by this push:
new 644aa7caff8 [v3-0-test] fix: task-sdk AssetEventOperations.get to use alias_name when specified (#52303) (#52324)
644aa7caff8 is described below
commit 644aa7caff84c1d859a05774c95f47173d9fd4b7
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Fri Jun 27 17:11:40 2025 +0800
[v3-0-test] fix: task-sdk AssetEventOperations.get to use alias_name when specified (#52303) (#52324)
* Fix AssetEventOperations.get to use alias_name when specified
* Use syntax compatible with python 3.9
(cherry picked from commit ac9e968fe85cf43717d280f303470eb5268ca9ca)
Co-authored-by: Justyn Harriman <jh...@openai.com>
---
task-sdk/src/airflow/sdk/api/client.py | 2 +-
task-sdk/tests/task_sdk/api/test_client.py | 47 ++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/task-sdk/src/airflow/sdk/api/client.py b/task-sdk/src/airflow/sdk/api/client.py
index 89bee9807e1..36489d3d79d 100644
--- a/task-sdk/src/airflow/sdk/api/client.py
+++ b/task-sdk/src/airflow/sdk/api/client.py
@@ -546,7 +546,7 @@ class AssetEventOperations:
if name or uri:
resp = self.client.get("asset-events/by-asset", params={"name": name, "uri": uri})
elif alias_name:
- resp = self.client.get("asset-events/by-asset-alias", params={"name": name})
+ resp = self.client.get("asset-events/by-asset-alias", params={"name": alias_name})
else:
raise ValueError("Either `name`, `uri` or `alias_name` must be provided")
diff --git a/task-sdk/tests/task_sdk/api/test_client.py b/task-sdk/tests/task_sdk/api/test_client.py
index ce532919749..7fa17ba1c4d 100644
--- a/task-sdk/tests/task_sdk/api/test_client.py
+++ b/task-sdk/tests/task_sdk/api/test_client.py
@@ -28,6 +28,7 @@ from task_sdk import make_client, make_client_w_dry_run, make_client_w_responses
from airflow.sdk.api.client import RemoteValidationError, ServerResponseError
from airflow.sdk.api.datamodels._generated import (
+ AssetEventsResponse,
AssetResponse,
ConnectionResponse,
DagRunState,
@@ -875,6 +876,52 @@ class TestConnectionOperations:
assert result.error == ErrorType.CONNECTION_NOT_FOUND
+class TestAssetEventOperations:
+ @pytest.mark.parametrize(
+ "request_params",
+ [
+ ({"name": "this_asset", "uri": "s3://bucket/key"}),
+ ({"alias_name": "this_asset_alias"}),
+ ],
+ )
+ def test_by_name_get_success(self, request_params):
+ def handle_request(request: httpx.Request) -> httpx.Response:
+ params = request.url.params
+ if request.url.path == "/asset-events/by-asset":
+ assert params.get("name") == request_params.get("name")
+ assert params.get("uri") == request_params.get("uri")
+ elif request.url.path == "/asset-events/by-asset-alias":
+ assert params.get("name") == request_params.get("alias_name")
+ else:
+ return httpx.Response(status_code=400, json={"detail": "Bad Request"})
+
+ return httpx.Response(
+ status_code=200,
+ json={
+ "asset_events": [
+ {
+ "id": 1,
+ "asset": {
+ "name": "this_asset",
+ "uri": "s3://bucket/key",
+ "group": "asset",
+ },
+ "created_dagruns": [],
+ "timestamp": "2023-01-01T00:00:00Z",
+ }
+ ]
+ },
+ )
+
+ client = make_client(transport=httpx.MockTransport(handle_request))
+ result = client.asset_events.get(**request_params)
+
+ assert isinstance(result, AssetEventsResponse)
+ assert len(result.asset_events) == 1
+ assert result.asset_events[0].asset.name == "this_asset"
+ assert result.asset_events[0].asset.uri == "s3://bucket/key"
+
+
class TestAssetOperations:
@pytest.mark.parametrize(
"request_params",