Skip to content

Refresh asset context after unmapping a task - #75751

Merged
uranusjr merged 3 commits into
apache:mainfrom
astronomer:fix-mapped-task-asset-context
Nov 26, 2026
Merged

uranusjr merged 3 commits into
apache:mainfrom
astronomer:fix-mapped-task-asset-context

Conversation

@uranusjr

@uranusjr uranusjr commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

A mapped task's template context is built from the MappedOperator, whose inlets and outlets only come from partial(). Anything the operator's __init__ added was missing from context["inlets"], ["outlets"], ["inlet_events"] and ["asset_state_store"]. For example, a mapped sensor that adds its asset in __init__ gets a KeyError from context["inlet_events"][asset] (#70225).

context_update_for_unmapped now refreshes these entries from the unmapped task. To keep this free of extra supervisor calls, InletEventsAccessors and AssetStateStoreAccessors no longer resolve asset refs and aliases when constructed. The task runner builds their lookups in _prepare(), after unmapping and before task code runs. The accessors created before unmapping are never built, and task code (including async code) never triggers a lookup.

Behavior changes:

  • A mapped task's context["inlets"] and ["outlets"] are now the task's own lists, as for non-mapped tasks.
  • If a mapped operator's __init__ adds a second asset, context["asset_state_store"].get(...) without a subscript raises ValueError, as it does for non-mapped tasks.
  • An inlet ref to an unknown asset now fails in _prepare() instead of at task startup. The task still fails before execute().

The asset state store accessor classes are also converted to attrs.

@uranusjr uranusjr changed the title Refresh asset context entries after unmapping Lazy-resolve inlet refs and refresh asset context Oct 27, 2026
@uranusjr

uranusjr commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

@uranusjr
uranusjr force-pushed the fix-mapped-task-asset-context branch from d9f8f62 to f4f2f27 Compare November 17, 2026 09:57
@uranusjr uranusjr changed the title Lazy-resolve inlet refs and refresh asset context Refresh asset context after unmapping a task Nov 17, 2026
A mapped task's template context is built from the MappedOperator,
whose inlets and outlets only come from partial(). Anything the
operator's __init__ added was missing from the asset entries of the
context, so e.g. a mapped sensor adding its asset in __init__ got a
KeyError from context["inlet_events"][asset].

context_update_for_unmapped now refreshes inlets, outlets, inlet_events
and asset_state_store from the unmapped task. To avoid duplicate
supervisor calls, the asset accessors no longer resolve refs and
aliases on construction; the task runner builds their lookups in
_prepare(), after unmapping and before task code runs, so the lookups
are never built from async task code.
@uranusjr
uranusjr force-pushed the fix-mapped-task-asset-context branch from f4f2f27 to 6219a84 Compare November 26, 2026 05:50
@uranusjr
uranusjr enabled auto-merge (squash) November 26, 2026 05:53
@uranusjr
uranusjr merged commit 213ff3c into apache:main Nov 26, 2026
187 of 189 checks passed
@uranusjr
uranusjr deleted the fix-mapped-task-asset-context branch November 26, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants