Re: [Mako] Error : TypeError: 'Undefined' object is not callable

82 views
Skip to first unread message
Message has been deleted

Mike Bayer

unread,
Dec 15, 2020, 1:35:44 PM12/15/20
to mako-d...@googlegroups.com
how about the actual template file?   I would need to run your .mako template to see why this is happening.   you would need to narrow down your problem to a single mako template since I can't run your whole application here.



On Tue, Dec 15, 2020, at 1:23 PM, Vikas Dubey wrote:
Dear all, 

I am trying to migrate a software to python2 to python3. I am not experienced with Mako templates. In my case, everything works in python2. However, python3 fails with the following error message:

Traceback (most recent call last):
  File "test.py", line 16, in <module>
    calibration.trigger_overall_calibration(**d)
  File "/home/vikas/Desktop/RevealCX3/smd/views/calibration.py", line 1370, in trigger_overall_calibration
    return calc_overall_calibration(_request, requested_from_server)
  File "/home/vikas/Desktop/RevealCX3/smd/views/calibration.py", line 1423, in calc_overall_calibration
    job = diff_overall_calibration(session_id, 
  File "/home/vikas/Desktop/RevealCX3/smd/lib/asynch/calibration.py", line 209, in diff_overall_calibration
    html = tmp.render(**{'orientation': orientation, 'calibrators': clb,
  File "/home/vikas/Desktop/RevealCX3/env/lib/python3.8/site-packages/mako/template.py", line 476, in render
    return runtime._render(self, self.callable_, args, data)
  File "/home/vikas/Desktop/RevealCX3/env/lib/python3.8/site-packages/mako/runtime.py", line 881, in _render
    _render_context(
  File "/home/vikas/Desktop/RevealCX3/env/lib/python3.8/site-packages/mako/runtime.py", line 924, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/home/vikas/Desktop/RevealCX3/env/lib/python3.8/site-packages/mako/runtime.py", line 952, in _exec_template
    callable_(context, *args, **kwargs)
  File "/tmp/mako_modules/v2/base.mak.py", line 110, in render_body
    __M_writer(str(next.body()))
  File "_home_vikas_Desktop_RevealCX3_smd_templates", line 215, in render_body
TypeError: 'Undefined' object is not callable


I am concerned with  __M_writer(str(next.body())), which is failing in writing the body. it also returns the same error if I do print(next.body()).

Here is a link to base.mak.py file if that helps:


Any help and comments will be appreciated.


--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mako-discuss...@googlegroups.com.

Message has been deleted

Mike Bayer

unread,
Dec 15, 2020, 2:23:27 PM12/15/20
to mako-d...@googlegroups.com
the stack trace indicates that the well-known name "body" is somehow being overwritten with an Undefined object.   I don't know why this is and your template is not something I can run without supporting infrastructure, unfortunately, as it makes many references to many different bits of state.

to debug your problem, you need to iteratively remove elements from this template until the issue no longer reproduces, and you get a non-error result (one with much less functionality for sure).   identifying the specific line of code that triggers the issue is the first step in isolating a problem.


On Tue, Dec 15, 2020, at 2:14 PM, Vikas Dubey wrote:
Thanks for the quick response. I am attaching  a template base.mak file. Let me know if it works for you. 
Can you perhaps give some insights about the error, when it may come from?  I am almost looking 2 days with no significant development.

Some more info:
Original Python2 version of the software used : mako==0.8.1
However, mako==1.1.3 also works for python2 software

For python3, I am using mako==1.1.3, the problem persists even if I downgrade mako==0.8.1
version of sqlalchemy==1.3.20



You received this message because you are subscribed to a topic in the Google Groups "Mako Templates for Python" group.
To unsubscribe from this group and all its topics, send an email to mako-discuss...@googlegroups.com.


--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mako-discuss...@googlegroups.com.

Vikas Dubey

unread,
Dec 15, 2020, 2:31:29 PM12/15/20
to mako-d...@googlegroups.com
Thanks for your reply. I will try your suggestion. 

Vikas Dubey

unread,
Dec 16, 2020, 7:02:06 AM12/16/20
to mako-d...@googlegroups.com
Hi Mike, 

Thanks for your reply and help. I managed to solve the issue. I found in the old mak templates there were multiple occurrences of unicode(something), which was not compatible with python3. I just replaced str() and everything worked fine. So, it was unrelated to mako.

Thanks,
Reply all
Reply to author
Forward
0 new messages