Skip to content

fix(eager): don't nest import aliases under a parent import that has finished - #1368

Merged
mnobile-hs merged 1 commit into
masterfrom
fix/eager-import-alias-shadowed-by-local
Nov 19, 2026
Merged

mnobile-hs merged 1 commit into
masterfrom
fix/eager-import-alias-shadowed-by-local

Conversation

@mnobile-hs

Copy link
Copy Markdown
Contributor

Description

In eager execution, an aliased import inside a macro from another aliased import resolves the parent alias by name from the calling scope. If the caller has a local variable with the same name as that alias, the lookup finds the variable instead of the import's alias map. Default execution mode doesn't do this lookup, so eager output diverges from it:

  • Local isn't a dict: rendering fails with InterpretException: Encountered a problem with import alias maps.
  • Local is a dict: the new import is silently added to the user's dict, e.g. {'name': 'local'} renders as {'name': 'local', 'printer': {}}.

For example, with {% import 'a.jinja' as outer %}{{ outer.render() }}, where render() in a.jinja does {% set outer = ... %} and then {% import 'b.jinja' as printer %}.

AliasedEagerImportingStrategy nests a child import's alias map under its parent's (outer.printer) so nested imports are reconstructed correctly while the parent is being imported. It now only does that while the parent import is still in progress, which it detects with the parent's temporary import alias, the same check EagerSetTagStrategy uses. Once the parent import has finished, the alias is bound in the current scope, like a top-level import and like default mode.

Testing

  • EagerImportTagTest.itImportsInsideMacroWhenLocalVariableShadowsParentAlias: a string local shadowing the parent alias no longer throws.
  • EagerImportTagTest.itDoesNotAddImportAliasToLocalDictShadowingParentAlias: a dict local shadowing the parent alias is left unchanged.
  • Both fail without the fix. The full test suite passes.

This description was authored by Claude Code.

🤖 Generated with Claude Code

…d importing

An aliased import inside a macro from another aliased import (e.g. a macro in
`{% import 'a.jinja' as outer %}` that does `{% import 'b.jinja' as inner %}`) built
the dotted alias `outer.inner` and walked `outer` by name from the calling scope to
nest the new alias map. Once the parent import has finished, that lookup can hit a
local variable instead of the alias map, which either threw "Encountered a problem
with import alias maps" (local is not a map) or put `inner` into the user's dict
(local is a map). Default execution mode has neither problem, so eager output
diverged from default output.

Only nest while the parent import is still in progress (its temporary import alias
is in scope), the same check EagerSetTagStrategy uses; otherwise bind the alias in
the current scope like a top-level import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mnobile-hs mnobile-hs self-assigned this Nov 19, 2026
@mnobile-hs
mnobile-hs marked this pull request as ready for review November 19, 2026 21:20
@mnobile-hs
mnobile-hs merged commit b83755e into master Nov 19, 2026
7 checks passed
@mnobile-hs
mnobile-hs deleted the fix/eager-import-alias-shadowed-by-local branch November 19, 2026 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants