Edgewall Software
Modify

Opened 3 years ago

Last modified 9 months ago

#12547 new defect

cursor.execute() requires list or tuple for 2nd argument in bugzilla2trac.py

Reported by: Jun Omae Owned by:
Priority: normal Milestone: next-stable-1.2.x
Component: contrib Version:
Severity: normal Keywords: bugzilla2trac
Cc: Branch:
Release Notes:
API Changes:

Description

I noticed this issue while reading r15012.

>>> import MySQLdb
>>> conn = MySQLdb.connect(user='root')
>>> cursor = conn.cursor()
>>> cursor.execute('SELECT %s', 'blah')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/py25/lib/python2.5/site-packages/MySQLdb/cursors.py", line 187, in execute
    query = query % tuple([db.literal(item) for item in args])
TypeError: not all arguments converted during string formatting
>>> cursor.execute('SELECT %s', ['blah'])
1L
>>> list(cursor)
[('blah',)]

I think the following code should use a list and bugzilla2trac.py currently doesn't work….

     def getLoginName(self, cursor, userid):
         if userid not in self.loginNameCache:
-            cursor.execute("SELECT * FROM profiles WHERE userid = %s", (userid))
+            cursor.execute("SELECT * FROM profiles WHERE userid = %s",
+                           [userid])
             loginName = cursor.fetchall()

Untested patch: bugzilla2trac.diff.

Attachments (1)

bugzilla2trac.diff (3.5 KB ) - added by Jun Omae 3 years ago.

Download all attachments as: .zip

Change History (5)

by Jun Omae, 3 years ago

Attachment: bugzilla2trac.diff added

comment:1 by Ryan J Ollos, 3 years ago

Keywords: bugzilla2trac added

I think it would be a good idea to just go ahead and commit this since it looks like the script is completely broken. From the other open tickets it looks like there is a lot of work to do on bugzilla2trac and we could fix other problems later.

Also, we could use a tuple rather than list, (fieldid,), which seems to be the more common style used throughout the Trac codebase.

Last edited 3 years ago by Ryan J Ollos (previous) (diff)

comment:2 by Ryan J Ollos, 2 years ago

Milestone: next-stable-1.0.xnext-stable-1.2.x

Moved ticket assigned to next-stable-1.0.x since maintenance of 1.0.x is coming to a close. Please move the ticket back if it's critical to fix on 1.0.x.

comment:3 by Peter Suter, 9 months ago

([15027] referenced this ticket instead of #9612.)

comment:4 by Ryan J Ollos, 9 months ago

Minor fix to bugzilla2trac.py in r16664, merged in r16665, r16666.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set.
The owner will be changed from (none) to anonymous.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.