Skip to content

Fix bug with imported macros and template globals#1241

Merged
davidism merged 2 commits intopallets:masterfrom
MLH-Fellowship:macros_with_globals
Jun 22, 2020
Merged

Fix bug with imported macros and template globals#1241
davidism merged 2 commits intopallets:masterfrom
MLH-Fellowship:macros_with_globals

Conversation

@amy-lei
Copy link
Copy Markdown
Contributor

@amy-lei amy-lei commented Jun 22, 2020

Fixes #688

  • Added parameter to _get_default_module to take in the current context and make a new module if template globals are found
  • Added self.globals to the Context class to differentiate between template variables from render variables.

Comment thread src/jinja2/environment.py
Comment thread src/jinja2/environment.py Outdated
Comment thread src/jinja2/environment.py
Comment thread src/jinja2/runtime.py Outdated
Comment thread src/jinja2/environment.py Outdated
@davidism
Copy link
Copy Markdown
Member

davidism commented Jun 22, 2020

_get_default_module is sort of misnamed now, since it will get a default module, or a new module for a new import. 🤔 Nothing needs to change, just adding an observation.

@davidism davidism force-pushed the macros_with_globals branch from 9276aa7 to acf193b Compare June 22, 2020 16:45
_get_default_module takes an optional context to indicate that the
template is imported. If there are differences between the environment
and rendered template globals, a new module is used for the imported
template.
@davidism davidism force-pushed the macros_with_globals branch from acf193b to cc792d8 Compare June 22, 2020 16:56
@davidism davidism added this to the 3.0.0 milestone Jun 22, 2020
@davidism davidism merged commit 9b718ed into pallets:master Jun 22, 2020
@davidism davidism deleted the macros_with_globals branch June 22, 2020 17:12
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Including a macro does not allow access to template globals.

2 participants