Skip to content

fix(eager): keep nested import alias paths consistent with flattened parent imports - #1369

Open
mnobile-hs wants to merge 2 commits into
masterfrom
fix/eager-nested-import-after-flattened-parent
Open

mnobile-hs wants to merge 2 commits into
masterfrom
fix/eager-nested-import-after-flattened-parent

Conversation

@mnobile-hs

@mnobile-hs mnobile-hs commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

#1368 stopped nesting an aliased import's alias map under its parent's once the parent import has finished, and binds it in the current scope instead. The import's full alias was still recorded as the dotted parent.child path, though. Imports inside the child file use that path to find where to nest their own alias maps, so a file imported this way that has its own top-level aliased import walks parent.child, finds nothing at child, and fails with InterpretException: Encountered a problem with import alias maps. The error aborts the whole macro call, so eager output is missing everything the macro would have rendered, while default execution mode renders it normally.

For example, with {% import 'outer.jinja' as outer %}{{ outer.render() }}, where render() in outer.jinja does {% import 'middle.jinja' as middle %}{{ middle.go() }} and middle.jinja starts with {% import 'printer.jinja' as printer %}.

The same failure happens without a top-level import when the outer macro is called inside a deferred block: while the deferred macro runs, the child import's temporary alias is in scope, so an import inside one of the child file's macros also treats its flattened parent as still importing and walks the stale dotted path.

  • AliasedEagerImportingStrategy now decides once, in its constructor, whether the import nests under its parent (only while the parent import is still in progress, the same check fix(eager): don't nest import aliases under a parent import that has finished #1368 added), and builds the full import alias from that decision.
  • A flattened import records its own alias as its full import alias, so imports inside it nest under its alias map's actual location.
  • constructFullAliasPathMap always walks the full import alias, which now matches where the maps live.

Testing

  • EagerImportTagTest.itImportsTopLevelAliasOfFileImportedInsideMacroFromAliasedImport fails without this change with Encountered a problem with import alias maps, and passes with it.
  • EagerImportTagTest.itImportsInsideMacroOfImportFromMacroCalledInDeferredBlock fails without this change with the same error, and passes with it.
  • The two tests added in fix(eager): don't nest import aliases under a parent import that has finished #1368 still pass.
  • The full suite passes: 2,251 tests, 0 failures, 23 skipped.

This description was authored by Claude Code.

🤖 Generated with Claude Code

Since #1368, an aliased import inside a macro from another aliased import is
bound in the current scope once the parent import has finished, instead of
being nested under the parent's alias map. Its full import alias was still the
dotted `parent.child` path, though, and that is the path any import inside the
child file walks to find where to nest its own alias map.

So if a file imported this way has its own top-level aliased import, that
import walks `parent.child`, finds nothing at `child`, and fails with
"Encountered a problem with import alias maps". The error aborts the whole
macro call, and eager output loses everything the macro would have rendered.
Default execution mode renders it normally.

Decide once, in the constructor, whether to nest under the parent (only while
the parent import is still in progress), and build the full import alias from
that decision. Imports inside a flattened import then nest under its alias
map's actual location.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mnobile-hs mnobile-hs self-assigned this Nov 23, 2026
…block

While a macro runs in a deferred block, the temporary alias of the import it
came from is in scope. Before the previous commit, an import inside one of that
file's macros therefore treated its flattened parent as still importing and
walked the stale dotted alias, failing with "Encountered a problem with import
alias maps".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant