Opened 5 years ago

If accidentally create a form with two input fields with the same ID, after first edit it fails to load the page

Reported by: Owned by: sylvix.dh@… normal TracFormsPlugin normal invalid markup 0.11

Description

Hello. I'm using TracFormsPlugin r12970 with the following trac installation (only relevant information):

 Trac 1.0.1 Genshi 0.7 (without speedups) pysqlite 2.6.0 Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] SQLite 3.7.9

I'm using the default sqlite database that trac offered me while creating environment.

If I accidentally create a form with two fields with the same ID, after first edit it fails to open the page I added the form to, with the following error:

AttributeError: 'list' object has no attribute 'replace'

File "/usr/local/lib/python2.7/dist-packages/trac/wiki/templates/wiki_view.html", line 49, in <Expression u'wiki_to_html(context, text)'>
File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 1546, in format_to_html
File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 1501, in generate
File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 1244, in format
File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 1134, in handle_code_block
File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 356, in process
File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 343, in _macro_processor
File "/home/tsyganov/projects/trac-plugins/TracFormsPlugin/trunk/0.11/tracforms/macros.py", line 48, in expand_macro
File "/home/tsyganov/projects/trac-plugins/TracFormsPlugin/trunk/0.11/tracforms/macros.py", line 133, in execute
File "/home/tsyganov/projects/trac-plugins/TracFormsPlugin/trunk/0.11/tracforms/macros.py", line 638, in _xml_escape



Here is the form I worked on (I only changed the labels). Two pairs of fields with the same ID are at the end:

#! TracForm
#! track_fields
|| Routine || Time, h || Result ||
|| Label 1 || [tf.input:deployment.time.note '' 3] || [tf.input:deployment.result.note '' 5] ||
|| Label 2 || [tf.input:deployment.time.adhoc '' 3] || [tf.input:deployment.result.adhoc '' 5] ||
|| Label 3 || [tf.input:deployment.time.ship '' 3] || [tf.input:deployment.result.ship '' 5] ||
|| Label 4 || [tf.input:deployment.time.test '' 3] || [tf.input:deployment.result.test '' 5] ||
|| Label 5 || [tf.input:deployment.time.test '' 3] || [tf.input:deployment.result.test '' 5] ||


So, the plugin saves the data of the same id as the list of values (here is the result of the selection with sqlite3):

sqlite> select * from forms where realm = 'wiki';


Here you can see the "deployment.result.test":["afdsf","afdsf"] and "deployment.time.test":["5","5"] values.

As the quick fix, I added two following lines to the macros.py file at line 131:

        for name, value in json.loads(state or '{}').iteritems():
if isinstance(value, list):
value = value[0]
self.env[name] = _xml_escape(value)


Please tell me if I'm doing anything wrong or if the problem exists, if there is another way to prevent this from happening (disallow saving forms with same IDs or something like that).

Dmitrii

comment:1 Changed 5 years ago by sylvix.dh@…

Sorry, I mean r11562 (last commit revision according to svn log in trunk/0.11 directory).

comment:2 in reply to:  description Changed 5 years ago by Steffen Hoffmann

Keywords: invalid markup added → 0.11

Hello. I'm using TracFormsPlugin r12970 with the following trac installation (only relevant information):

Thanks for sharing comprehensive information, most appreciated apart from taking your time to report in general.

If I accidentally create a form with two fields with the same ID, after first edit it fails to open the page I added the form to, with the following error:

AttributeError: 'list' object has no attribute 'replace'


... I see. Yes, this is a know issue and recurring in my own production environments too. Sadly, I've not bothered to fix it until now, because I felt the appropriate workaround was to delete form values by resetting from form details page (the link in Trac context menu) and fix you form.

No, if I would apply you fix, the error in the bad form could go unnoticed, and possibly even precious values overwritten unnoticed, because only one field content can win, if you have two.

Please tell me if I'm doing anything wrong or if the problem exists, if there is another way to prevent this from happening (disallow saving forms with same IDs or something like that).

As it stands for now, if we and up with a list, it's always wrong. We may wish to act more graceful right, but not completely hide the issue, like your fix would do. That's not to deprive you, since you took your precious time to investigate and even elaborate on the code towards a fix, even publish it here.

What I say is: Let's do a bit better by not allowing to save bad forms. IIRC this was meant to be so once before I took over maintenance of this plugin in my early Python days. Likely I've broken something without knowing enough about the code, that would have refused form rendering before one could do the first commit and demand fixing of the form right-away.

comment:3 Changed 12 months ago by Ryan J Ollos

Owner: Steffen Hoffmann deleted

Modify Ticket

Change Properties
Action
as new The ticket will remain with no owner.