Type asset_expression in the REST API so the UI does not cast through unknown
closes: #67692
asset_expression was declared as dict | None on the REST API response models, so the OpenAPI generator emitted { [k: string]: unknown }. The UI compensated by hand-maintaining an ExpressionType discriminated union in src/components/AssetExpression/ and casting the API value through it with no runtime check, so a change to the server shape would not be caught by the TypeScript build. This types the expression on the API side and lets the generated client describe it.
What changed:
- Added a structured
AssetExpressionmodel indatamodels/common.py: a recursive discriminated union over the five shapesBaseAsset.as_expression()produces (asset,alias,asset_ref,any,all), following the existingAnnotated[Union[...], Discriminator]pattern in that module. Asset leaves carry theidthatDagModelOperation.update_dag_asset_expressioninjects when the expression is persisted.idis optional so a row written before id-enrichment, or migrated from the pre-3.0 dataset format, still validates instead of returning a 500. - Used the model for every response that serves the field:
DAGDetailsResponse,DAGWithLatestDagRunsResponse, and both fields on the partitioned dag run responses. - Typed the
next_run_assetsUI endpoint with a newNextRunAssetsResponsemodel indatamodels/ui/assets.pyinstead of a baredict.response_model_exclude_unset=Truekeeps the response shape identical to before. - Regenerated the OpenAPI spec and the TypeScript client.
- Removed the hand-maintained
ExpressionTypeunion and the casts inAssetProgressCell.tsxandAssetSchedule.tsx; the UI now consumes the generated type. The more precise types also let some now-dead defensive code inAssetExpression.tsxbe removed.
For expressions produced by the current code the emitted JSON is unchanged, so this is not a breaking change for API consumers; only the declared schema becomes precise.
Tests: added test_common.py covering round-trip serialization of every variant, the optional id behaviour, and rejection of malformed shapes. Updated the test_get_dags fixtures, which set asset_expression to a simplified {"any": [{"uri": ...}]} shape that as_expression() never produces and that the new model correctly rejects, to the real {"any": [{"asset": {...}}]} shape. The next_run_assets and dag-detail route tests pass unchanged.
Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code (Claude Opus 4.8), reviewed and verified by the author
[!IMPORTANT] 🛠️ Maintainer triage note for @Anuragp22 · by
@potiuk· 2026-06-12 10:47 UTCYour review threads look addressed — please confirm this PR is ready for maintainer review confirmation.
Feedback from
@bbovenziacross 3 unresolved thread(s); you've engaged with each (replies and/or pushes since).The ball is in your court — you've been assigned to this PR. Reply
yes / readyand a maintainer will pick it up from the queue.Automated triage — may be imperfect; a maintainer takes the next look.
Rebased onto main and fixed the failing tests.
The /dags failures came from the test_get_dags fixtures, which set asset_expression to a simplified {"any": [{"uri": ...}]} shape that BaseAsset.as_expression() never produces. It was accepted while the field was an untyped dict, but the new model correctly rejects the bare leaf. I updated the fixtures to the real {"any": [{"asset": {...}}]} shape. The full api_fastapi suite passes locally.
The force-push is that rebase: I rebased onto current main to clear the merge conflict and squashed the work into a single commit (d88ce26 to 622dc91). No content changed beyond the test fixtures.
Merged main, which now includes AIP-76 (#64571). AIP-76 rewrote the same asset_expression code, so resolving the overlap grew the diff.
What changed since the last review:
-
Extended the typing to the partitioned-dag-run responses AIP-76 added (
PartitionedDagRunCollectionResponse,PartitionedDagRunDetailResponse), alongside the originalDAGDetailsResponse,DAGWithLatestDagRunsResponse, andNextRunAssetsResponse. -
AIP-76 builds the
next_run_assetsand partitioned responses from a dict via explicit constructors. Sinceasset_expressionis now typed, those routes usemodel_validate({...})so pydantic validates the stored dict into the model. This mirrorsDAGDetailsResponse.model_validate(dag_model)inroutes/public/dags.pyand leaves AIP-76's partition logic unchanged. -
Addressed the earlier review:
ExpressionTypeis now derived from the generated client,AssetSummaryis removed, and theas ExpressionTypecasts inAssetProgressCell.tsxandAssetSchedule.tsxare gone. Also removed the now-unusedNextRunEventtype. -
Regenerated the OpenAPI spec and TypeScript client.
Ready for maintainer review.
Two commits since the last look:
-
Fixed the
ruff-formatfailure onpartitioned_dag_runs.py, the only red check. -
Hardened the newly-typed
asset_expressionfield against pre-3.0 migrated rows. The 2.x dataset scheduler stored shapes the 3.0 column rename carried over verbatim: a bare URI string,{"any": [<strings>]},{"alias": "<name>"}. The typed field would return a 500 on those until the DAG is re-parsed.MaybeAssetExpressionnow coerces any unrecognized stored shape tonull, reproducing the blank render the UI showed while the field was an untyped dict. Added round-trip and coercion tests.
I've addressed all three of bbovenzi's comments on AssetExpression/types.ts.
ready
@Anuragp22 — the Static checks CI job is failing here, which needs a code fix on your side (a rerun won't clear it). You can reproduce and fix locally with:
pre-commit run --all-files # or: breeze static-checks
Once those pass and CI is green, it'll be ready for a maintainer to pick up. Thanks!
See the PR quality criteria.
Automated first-pass triage note drafted by an AI-assisted tool — may get things wrong; once addressed, a real Apache Airflow maintainer takes the next look. (why automated)
Drafted-by: Claude Code (Opus 4.8); reviewed by @potiuk before posting
Besides the unresolved comment, lgtm!
Backport failed to create: airflow-ctl/v0-1-test. View the failure log Run details
Note: As of Merging PRs targeted for Airflow 3.X the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
In matter of doubt please ask in #release-management Slack channel.
| Status | Branch | Result |
|---|---|---|
| ❌ | airflow-ctl/v0-1-test |
You can attempt to backport this manually by running:
cherry_picker 3733e62 airflow-ctl/v0-1-test
This should apply the commit to the airflow-ctl/v0-1-test branch and leave the commit in conflict state marking the files that need manual conflict resolution.
After you have resolved the conflicts, you can continue the backport process by running:
cherry_picker --continue
If you don't have cherry-picker installed, see the installation guide.