Comments you submit will be routed for moderation. If you have an account, please log in first.
Modify

Ticket #3876 (closed defect: fixed)

Opened 8 years ago

Last modified 8 years ago

Tracmoderator 0.4 and 0.5 doesn't work anymore

Reported by: Alwin <trac@…> Owned by: jdsiiro
Priority: blocker Milestone:
Component: TracTicketModerator Version:
Keywords: Cc:

Description

Hi,

I'd tried to upgrade moderator-plugin to 0.5, later downgrade to 0.4. Environment is trac 0.11.4 with mysql as backend.

Problems:

in moderator 0.5 I get an exception

TracTicketModerator-0.5.1-py2.4.egg/ticketmoderator/web_ui.py", line 533, in __init__
    self[field] = eval(tmp_v)
  File "<string>", line 1
     {'field_type': u'defect', 'field_status': u'new', 'author': u'anonymous', 'field_severity': u'tweak', 'submit': u'Create ticket', 'field_summary': u'Major bug! pro
blem analysis', 'field_priority': u'normal', '__FORM_TOKEN': u'2901f3e67a86cde0db3cc8b8', 'f

SyntaxError: EOL while scanning single-quoted string (line 1)

After a while I checked it results from a wrong column type in mysql: it was varchar(255) and the value put in was longer. Changed it to text. And now the problems start real:

Moderator inserted the complete array into this field. in version 0.5 you do something with re.sub, which did nothing (didn't find the searched substring) so the code results in

self[field] = eval(tmp_v)

got an exception:

web_ui.py", line 533, in __init__
    self[field] = eval(tmp_v)
TypeError: eval() arg 1 must be a string or code object

makes sense to me: tmp_v is an array object. Whatever you tried to eval, it does not work. Same in 0.4 without all the re.sub before.

TracTicketModerator-0.4-py2.4.egg/ticketmoderator/web_ui.py", line 434, in __init__
TypeError: eval() arg 1 must be a string or code object

the argument is an array object, not a string nor a code object. I real don't understand what you try doing there so I didn't find a workaround for that. Did you try assign the array to that field? I tried simply assing that array to the field (self[field] = value) but as expected it crashed again.

TracTicketModerator-0.5.1-py2.4.egg/ticketmoderator/web_ui.py", line 561, in load_ticket
    for name in self[source].keys():
AttributeError: 'array.array' object has no attribute 'keys'

So it feals like something in storing the values of moderation into a mysql database goes complete wrong. :(

This wonderful plugin is now complete useless to me, I'm real annoying that I tried to upgrade it.

May you give me a hint how to deal with it? My old 0.4.dev package I lost so I can not go back.

tnx

A.

Attachments

Change History

comment:1 Changed 8 years ago by jdsiiro

Referenced in changeset [2577]:

TicketModerator: end the bad practice of using str() / eval() for saving dictionaries to the database. The new_fields, orig_fields, and args dictionaries are now pickled before writing them to the db. This should resolve the problem reported in #3876.

comment:2 Changed 8 years ago by jdsiiro

I am not sure how you got into the situation that you ended up in, but to address some of your problems:


After a while I checked it results from a wrong column type in mysql: it was varchar(255) and the value put in was longer. Changed it to text.

I am not sure how you ended up with a VARCHAR(255) field. The Trac API /should/ generate tables where all text fields are actually TEXT fields. If you can consistently end up with VARCHAR columns instead of TEXT, please let me know, but I suspect this is an upstream bug in Trac. :(


I real don't understand what you try doing there so I didn't find a workaround for that.

The TicketModerator has to save several dictionaries when it is saving a moderated submission (particularly, the request arguments, and the ticket fields from before and after the update). In the early implementation of the plugin, I used the "cheap" shortcut that if the dictionary is "simple" (contains only simple types), you can save the str() of the dict and later restore it by eval()ing the string. Somehow, you have managed to set something in one of those dictionaries to be an object that can't be correctly eval()ed.

So, the solution:

  • In general: r2577 switches the mechanism for saving data to use Python's pickle serialization (in the long term, this should be both safer and more robust)
  • For your specific case: if the database is currently in such a "bad" state that the plugin is failing, it is likely that the database upgrade procedure will also fail. If it does, you can safely drop the corrupt TicketModerator information without harming the rest of the database. Then the next time you enable the plugin, it will ask you to upgrade your database and you will get a clean TicketModerator environment. To do that:
    1. DROP TABLE moderator_tickets;
    2. DELETE FROM system WHERE name='ticketmoderator_version';

Right now, r2577 is available on trunk. I have a few other things I want to take a look at, but will try and push out a new release and publish new eggs before next week.

comment:3 Changed 8 years ago by jdsiiro

TicketModerator 0.6 has been released. Please let me know if it fixes these problems.

comment:4 follow-up: ↓ 5 Changed 8 years ago by trac@…

I tried to test it, but all I get is:

Trac[loader] ERROR: Skipping "ticketmoderator.api = ticketmoderator.api": (can't import "cannot import name empty")

:(

Tested with .egg from your side and own build, python 2.5 debian lenny, trac 0.11 - no idea whats going wrong now...

comment:5 in reply to: ↑ 4 Changed 8 years ago by jdsiiro

Replying to trac@…:

Trac[loader] ERROR: Skipping "ticketmoderator.api = ticketmoderator.api": (can't import "cannot import name empty")

This is a separate issue from the DB access problems, and appears to only be a problem with Trac 0.11. I have created #3889 to track this defect.

comment:6 Changed 8 years ago by jdsiiro

  • Status changed from new to closed
  • Resolution set to fixed

User confirmed things are working in comment:ticket:3889:2

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.