dabla commented on code in PR #74540:
URL: https://github.com/apache/airflow/pull/74540#discussion_r4724139251
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/asset_state_store.py:
##########
@@ -125,42 +130,42 @@ def _resolve_asset_id_by_uri(uri: str, session:
SessionDep) -> int:
@router.get("/by-name/value")
-def get_asset_state_store_by_name(
+async def get_asset_state_store_by_name(
name: Annotated[str, Query(min_length=1)],
key: Annotated[str, Query(min_length=1)],
- session: SessionDep,
+ session: AsyncSessionDep,
) -> AssetStateStoreResponse:
"""Get an asset state store value by asset name."""
- asset_id = _resolve_asset_id_by_name(name, session)
- if (value := get_state_backend().get_value(AssetScope(asset_id=asset_id),
key, session=session)) is None:
+ asset_id = await _resolve_asset_id_by_name(name, session)
+ if (value := await get_state_backend().aget(AssetScope(asset_id=asset_id),
key, session=session)) is None:
Review Comment:
**[blocker]** `aget` returns the stored JSON string, `get_value` returned
the decoded value: both GET routes now answer with the wrong value.
`main` calls `get_value()`, which decodes what `get()` returns. `aget()` is
the async twin of `get()`, not of `get_value()`, so the response now carries
the raw string (`{"value": "\"2026-04-29\""}` instead of `{"value":
"2026-04-29"}`, a dict comes back as a string), and a stored JSON `null`
answers 200 instead of 404. The async twin already exists:
[`aget_value`](https://github.com/apache/airflow/blob/3966b3c5179bb62dfce8920c61073b5115c4daa6/shared/state/src/airflow_shared/state/__init__.py#L288-L294).
It also keeps the override point for a backend that stores values natively.
```python
if (value := await
get_state_backend().aget_value(AssetScope(asset_id=asset_id), key,
session=session)) is None:
```
The same change is needed in `get_asset_state_store_by_uri` (line 233). On
this head, 9 of the 43 tests in `test_asset_state_store.py` fail
(`test_get_returns_value`, `test_get_stored_null_returns_404`,
`test_get_asset_name_with_slashes`, the four `test_put_*_roundtrip` /
`test_put_overwrites_existing`, for by-name and by-uri); with `aget_value` in
both handlers all 43 pass.
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/asset_state_store.py:
##########
@@ -67,9 +67,9 @@ class _TIWriterFields(NamedTuple):
try_number: int
-def _fetch_ti_writer_fields(token: TIToken, session: SessionDep) ->
_TIWriterFields:
- """Return exact writer attribution for the execution identified by the
token."""
- row = session.execute(
+async def _fetch_ti_writer_fields(token: TIToken, session: AsyncSessionDep) ->
_TIWriterFields:
+ """Return (dag_id, run_id, task_id, map_index) for the TI identified by
the token."""
Review Comment:
**[nit]** The rebase brought back an older docstring.
`main` says "Return exact writer attribution for the execution identified by
the token." The function returns eight fields (`task_instance_id`, `region_id`,
`region_index` and `try_number` included), so the four-field list is no longer
true. Keep the docstring of `main`.
##########
airflow-core/src/airflow/state/metastore.py:
##########
@@ -473,7 +473,7 @@ async def _aget_task_state_store(
self, scope: TaskScope, key: str, *, session: AsyncSession
) -> str | None:
row = await session.scalar(
- select(TaskStateStoreModel).where(
+ select(TaskStateStoreModel.value).where(
Review Comment:
**[nit]** Three of the four readers now select only `value`; the sync
`_get_task_state_store` (line 249, not in the diff) still loads the whole row.
Either change that one too, so the sync and async task readers stay the
same, or leave the task-state readers out of this PR, which is about the asset
state store routes. In the three changed readers `row` now holds the value
itself, so `return await session.scalar(...)` (and `return
session.scalar(...)`) says it without the misleading name.
--
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]