Add extra field filtering for asset events#64611
Merged
hussein-awala merged 6 commits intoJul 7, 2026
Merged
Conversation
aa2aac2 to
1f8e675
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for filtering asset events by extra JSON key/value pairs across the Airflow stack (Core REST API, Execution API, Task SDK), including client serialization, docs, and test coverage, plus a Postgres index intended to speed up containment queries.
Changes:
- Introduces repeated
extra=key=valuequery filtering for asset events in Core REST API and Execution API endpoints. - Extends Task SDK inlet event accessors and client/supervisor plumbing to forward
extrafilters. - Adds a new Postgres GIN index migration for
asset_event.extra, updates OpenAPI artifacts and documentation, and expands unit tests.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| task-sdk/tests/task_sdk/execution_time/test_supervisor.py | Updates supervisor request expectations to include extra, adds new request cases. |
| task-sdk/tests/task_sdk/execution_time/test_context.py | Adds accessor chaining tests for .extra(key, value) filtering. |
| task-sdk/tests/task_sdk/api/test_client.py | Adds tests verifying dict-to-repeated-query-param serialization for extra. |
| task-sdk/src/airflow/sdk/execution_time/supervisor.py | Forwards extra from supervisor messages to SDK client calls. |
| task-sdk/src/airflow/sdk/execution_time/context.py | Adds .extra() chaining on InletEventsAccessor and forwards extra to supervisor message. |
| task-sdk/src/airflow/sdk/execution_time/comms.py | Adds `extra: dict[str, str] |
| task-sdk/src/airflow/sdk/api/client.py | Serializes extra dict to repeated extra=key=value query parameters. |
| airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_asset_events.py | Adds Execution API tests for extra filtering for both by-asset and by-alias endpoints. |
| airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py | Adds Core REST API tests for extra filtering and combinations. |
| airflow-core/src/airflow/utils/sqlalchemy.py | Adds JsonContains custom SQL construct for dialect-aware JSON containment. |
| airflow-core/src/airflow/utils/db.py | Updates migration head mapping for Airflow 3.3.0. |
| airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts | Updates generated UI request types to include extra and adjusts ValidationError shape. |
| airflow-core/src/airflow/ui/openapi-gen/requests/services.gen.ts | Wires extra through generated UI service call parameters. |
| airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts | Updates generated UI schemas (including ValidationError changes). |
| airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts | Adds extra to generated suspense query hook signature/key. |
| airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts | Adds extra to generated query hook signature/key. |
| airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts | Adds extra to generated prefetch helper signature/key. |
| airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts | Adds extra to generated ensureQueryData helper signature/key. |
| airflow-core/src/airflow/ui/openapi-gen/queries/common.ts | Adds extra into the generated query-key function inputs. |
| airflow-core/src/airflow/migrations/versions/0111_3_3_0_add_gin_index_on_asset_event_extra.py | Adds a Postgres-only GIN index migration for asset_event.extra. |
| airflow-core/src/airflow/api_fastapi/execution_api/routes/asset_events.py | Adds extra filtering to Execution API asset-event endpoints. |
| airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py | Adds extra filter dependency to Core REST /assets/events. |
| airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml | Adds extra query parameter to OpenAPI and updates ValidationError schema. |
| airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml | Updates private UI OpenAPI components (including ValidationError changes). |
| airflow-core/src/airflow/api_fastapi/common/parameters.py | Adds reusable _JsonKVFilter and json_kv_filter_factory for JSON KV filtering. |
| airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/openapi-gen/requests/types.gen.ts | Updates generated auth-manager UI request types (ValidationError changes). |
| airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/openapi-gen/requests/schemas.gen.ts | Updates generated auth-manager UI schemas (ValidationError changes). |
| airflow-core/src/airflow/api_fastapi/auth/managers/simple/openapi/v2-simple-auth-manager-generated.yaml | Updates generated auth-manager OpenAPI components (ValidationError changes). |
| airflow-core/docs/migrations-ref.rst | Documents the new migration as the head revision. |
| airflow-core/docs/authoring-and-scheduling/assets.rst | Documents Task SDK chaining and REST API usage for extra filtering. |
Comments suppressed due to low confidence (1)
airflow-core/src/airflow/api_fastapi/execution_api/routes/asset_events.py:166
- The
/by-asset-aliasendpoint applies extra filtering viaAssetEvent.extra[k].as_string() == v, while/by-assetuses the new dialect-awareJsonContains. This creates inconsistent behavior across DB backends and duplicates parsing logic. Recommend reusing_parse_extra_params()here and applying a singleJsonContains(AssetEvent.extra, extra_dict)condition (like/by-asset) for consistent cross-dialect SQL and index usage on Postgres.
where_clause = AssetAliasModel.name == name
if after:
where_clause = and_(where_clause, AssetEvent.timestamp >= after)
if before:
where_clause = and_(where_clause, AssetEvent.timestamp <= before)
for item in extra:
if "=" in item:
k, v = item.split("=", 1)
where_clause = and_(where_clause, AssetEvent.extra[k].as_string() == v)
return _get_asset_events_through_sql_clauses(
join_clause=AssetEvent.source_aliases,
where_clause=where_clause,
session=session,
ascending=ascending,
limit=limit,
)
a4e93f2 to
ccfc953
Compare
e0a8dc3 to
bca926b
Compare
Add the ability to filter asset events by their extra JSON field using key-value pairs across the full stack: - Core REST API: new repeated `extra` query parameter on /assets/events (e.g. ?extra=region=us&extra=env=prod), combined with AND logic via a dialect-aware JsonContains construct. - Execution API: both /by-asset and /by-asset-alias accept repeated extra=key=value params. - Task SDK: InletEventsAccessor.extra(key, value) is chainable; client and supervisor forward the extra dict. - Postgres GIN index on asset_event.extra for efficient containment queries (created via raw SQL, excluded from non-Postgres backends). - Documentation, OpenAPI specs, UI clients, and tests. Co-authored-by: Cursor <cursoragent@cursor.com>
bca926b to
40cf0aa
Compare
choo121600
reviewed
Jun 27, 2026
choo121600
left a comment
Member
There was a problem hiding this comment.
overall looks good. It just seems to need a rebase.
…xtra-filtering # Conflicts: # airflow-core/docs/migrations-ref.rst # airflow-core/src/airflow/utils/db.py
pierrejeambrun
approved these changes
Jul 2, 2026
pierrejeambrun
left a comment
Member
There was a problem hiding this comment.
Thanks! LGTM.
We might one another pair of eyes on this since the change set is big.
shahar1
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add the ability to filter asset events by their
extraJSON field using key-value pairs across the full stack (Core REST API, Execution API, Task SDK).Changes
REST API (Core)
extrarepeated query parameter on the/assets/eventsendpoint (e.g.?extra=region=us&extra=env=prod).extraparams are combined with AND logic._JsonKVFilterparameter class backed by a dialect-awareJsonContainsSQL construct.Execution API
/by-assetand/by-asset-aliasendpoints acceptextraas a repeatedkey=valuequery parameter.Task SDK
InletEventsAccessor.extra(key, value)is chainable — each call accumulates into a dict for multi-condition filtering:GetAssetEventByAsset,GetAssetEventByAssetAlias) withextra: dict[str, str] | None.extra=key=valuequery params.extradict to the client.Dialect-aware JSON containment (
JsonContains)Compiles to database-native JSON containment on each backend:
@>JSONB containment (GIN-indexable).JSON_CONTAINS.json_extractcomparisons.All dialects use bound parameters to avoid SQL injection.
Database
asset_event.extra(extra::jsonb) for efficient containment queries. The index is created via raw SQL and excluded from non-PostgreSQL backends (handled inenv.pyand the schema-sync test).Documentation
assets.rstwith examples for both Task SDK chaining and REST API usage.Test plan