Roundup Tracker - Issues

Issue 2551026

classification
Title: template variable not defined even though it is
Type: Severity: major
Components: Web interface Versions: devel
process
Status: new Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: joseph_myers, rouilj, tekberg
Priority: Keywords: patch, python3

Created on 2019-03-04 21:04 by tekberg, last changed 2019-03-24 01:36 by rouilj.

Files
File name Uploaded Description Edit Remove
PythonExpr.py.diff tekberg, 2019-03-04 22:59 Patch file for PythonExpr.py
Messages
msg6364 Author: [hidden] (tekberg) Date: 2019-03-04 21:04
When using python 3.5 (probably fails with all python 3s), references to 
tal variables sometimes fail.

To reproduce, create the demo tracker.
Change html/issue.item.html
Locate the <table> element near line 42. Change it to this:

<table class="form"
       tal:define="user_realnames python:sorted('Kirk,Spock,Uhura, 
McCoy,Scotty,Sulu,Chekov,Chapel'.split(','));
		   bad_expression python:[x for x in context.assignedto 
if x.realname not in user_realnames]">

To make things simpler, in the config.ini file, set web.debug=yes.
Do whatever you need to do to deploy these two changes.
Go to the browser and bring up the demo tracker. Click on 'Create New' 
in the sidebar, you will get a 'Templating Error' with this detail at 
the top of the page:

<class 'NameError'>: name 'user_realnames' is not defined

If you do a browser search for 'user_realnames' it will match the name 
in the above error message, with the last match matching the variable 
which is actually defined with the correct value.

The problem is that roundup/cgi/PageTemplates/PythonExpr.py tries to 
obtain variables referenced in the python expression using this 
expression at line 43:

self._f.__code__.co_names

With python 3.5 this expression does not return all variables in the 
expression ('context', 'assignedto'). The same code for python 2.7 works 
fine and returns all variables in the expression ('context', 
'assignedto', 'realname', 'user_realnames').

I am working on a fix for this using the symtable package. I'll post it 
here when I'm finished. My proof of concept test code works for both 
python 2.7 and 3.5.
msg6365 Author: [hidden] (tekberg) Date: 2019-03-04 22:59
Here is a patch file generated using:

$ hg diff roundup/cgi/PageTemplates/PythonExpr.py

It works for me with Python 3.5. I assume it works for Python 2.7 since
my  proof of concept works with Python 2.7. Hopefully someone can verify
that. It might be nice if someone could review my code too.
msg6420 Author: [hidden] (rouilj) Date: 2019-03-24 01:16
Joseph, this looks like a python 3 issue.

Can you take a look at the patch and see if it looks ok for you.
I am kind of lost as to what magic is happening there.

There may be a better way to patch it and get rid of the problem
Tom found.

Tom do you have any test cases that we can run that will show the
problem and that go away when this patch is applied? The fact that this
slipped though indicates we need to enhance the test/test_templating.py
cases.

-- rouilj
History
Date User Action Args
2019-03-24 01:36:38rouiljsetkeywords: + python3
2019-03-24 01:16:56rouiljsetmessages: + msg6420
2019-03-24 01:14:18rouiljsetnosy: + joseph_myers
2019-03-04 22:59:34tekbergsetfiles: + PythonExpr.py.diff
keywords: + patch
messages: + msg6365
2019-03-04 21:04:58tekbergcreate