You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error with nested list comprehension when using strict_undefined=True #418
from mako.template import Template
text = """
<%
b = {}
bs = sorted(b, key=lambda b: sum(f for s in b.values() for f in s.values()))
%>
"""
tmpl = Template(text=text, strict_undefined=True)
out = tmpl.render()
print(out)
This produces the following error
Traceback (most recent call last):
File "memory:0x7164e2d38380", line 28, in render_body
File "/usr/local/lib/python3.12/dist-packages/mako/runtime.py", line 106, in __getitem__
return builtins.__dict__[key]
~~~~~~~~~~~~~~~~~^^^^^
KeyError: 's'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/sgr/Projects/Ganymede/digital/design/top_xt018_fx/titi.py", line 11, in <module>
out = tmpl.render()
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/mako/template.py", line 434, in render
return runtime._render(self, self.callable_, args, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/mako/runtime.py", line 874, in _render
_render_context(
File "/usr/local/lib/python3.12/dist-packages/mako/runtime.py", line 916, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/usr/local/lib/python3.12/dist-packages/mako/runtime.py", line 943, in _exec_template
callable_(context, *args, **kwargs)
File "memory:0x7164e2d38380", line 30, in render_body
NameError: 's' is not defined
Activity
sqla-tester commentedon Apr 10, 2025
Sébastien Granjoux has proposed a fix for this issue in the main branch:
Fix undeclared variables in nested list comprehension with strict_undefined https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/5861
zzzeek commentedon Apr 10, 2025
OK. I guess you want a release too :). it's thursday so that's good, in case this causes breakage (lots of PRs do).
zzzeek commentedon Apr 10, 2025
1.3.10 is out
sgranjoux commentedon Apr 10, 2025
Indeed a release was nice. Thank you, that's really fast.
Fix undeclared variables in nested list comprehension with strict_und…