Skip to content

Mako 1.3.7 breaks my code with "NameError: name 'n' is not defined" #415

@mgedmin

Description

@mgedmin

The project in question: https://github.com/mgedmin/project-summary.

A week ago it was building fine, and today I got an email from GitHub Actions telling me about build failures. I've narrowed down the cause to a mako version change: 1.3.7 breaks my test suite, 1.3.6 works fine. The errors look like this:

summary.py:1027: in stylesheet_rules
    Template(rule, default_filters=['str', 'n']).render_unicode(
.tox/py312/lib/python3.12/site-packages/mako/template.py:443: in render_unicode
    return runtime._render(
.tox/py312/lib/python3.12/site-packages/mako/runtime.py:874: in _render
    _render_context(
.tox/py312/lib/python3.12/site-packages/mako/runtime.py:916: in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
.tox/py312/lib/python3.12/site-packages/mako/runtime.py:938: in _exec_template
    _render_error(template, context, compat.exception_as())
.tox/py312/lib/python3.12/site-packages/mako/runtime.py:948: in _render_error
    result = template.error_handler(context, error)
.tox/py312/lib/python3.12/site-packages/mako/runtime.py:936: in _exec_template
    callable_(context, *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

context = <mako.runtime.Context object at 0x718d12ba4410>
pageargs = {'column': <summary.DateColumn object at 0x718d12ba7e00>, 'css_class': 'date', 'discrim': '.date', 'page': <summary.Page object at 0x718d12b9e060>}, __M_caller = None
__M_locals = {'pageargs': {'column': <summary.DateColumn object at 0x718d12ba7e00>, 'css_class': 'date', 'discrim': '.date', 'page': <summary.Page object at 0x718d12b9e060>}}
column = <summary.DateColumn object at 0x718d12ba7e00>, page = <summary.Page object at 0x718d12b9e060>, css_class = 'date'
__M_writer = <built-in method append of collections.deque object at 0x718d12b5d120>

    def render_body(context,**pageargs):
        __M_caller = context.caller_stack._push_frame()
        try:
            __M_locals = __M_dict_builtin(pageargs=pageargs)
            try:
                column = context['column']
            except KeyError:
                raise NameError("'column' is not defined")
            try:
                page = context['page']
            except KeyError:
                raise NameError("'page' is not defined")
            try:
                css_class = context['css_class']
            except KeyError:
                raise NameError("'css_class' is not defined")
            __M_writer = context.writer()
            if column.align:
                __M_writer('      #')
>               __M_writer(n(str(page.name)))
        # memory:0x718d12b9d220 line 2 in render_body:
        #       #${page.name} th.${css_class},
                __M_writer(' th.')
                __M_writer(n(str(css_class)))
E               NameError: name 'n' is not defined

memory:0x718d12b9d220:34: NameError

I'm rendering the template using

def Template(*args, **kw) -> mako.template.Template:
    kw.setdefault('default_filters', ['h'])
    return mako.template.Template(error_handler=mako_error_handler,
                                  strict_undefined=True,
                                  *args, **kw)

...
                Template(rule, default_filters=['str', 'n']).render_unicode(
                    page=page,
                    column=self,
                    css_class=self.css_class,
                    discrim=discrim,
                )

Is this missing something?

This is probably related to the fix for #140, but I don't understand that issue nor what I'm doing wrong here. The release notes are also not very helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions