Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#473 closed enhancement (fixed)

Make MySQL warnings more informative

Reported by: mlambert@… Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Sometimes when saving a record the data is slightly malformed and MySQL will raise an error. This code adds an extra debug wrapper layer for MySQL to make these warnings more informative.

In core/db/backends/, add the following class:

class MysqlDebugWrapper:

def init(self, cursor):

self.cursor = cursor

def execute(self, sql, params=[]):


result = self.cursor.execute(sql, params)

except Database.Warning, w:

self.cursor.execute("show warnings")
raise Database.Warning, "%s: %s" % (w,self.cursor.fetchall())

return result

def executemany(self, sql, param_list):


result = self.cursor.executemany(sql, param_list)

except Database.Warning:

self.cursor.execute("show warnings")
raise Database.Warning, "%s: %s" % (w,self.cursor.fetchall())

return result

def getattr(self, attr):

if self.dict.has_key(attr):

return self.dict[attr]


return getattr(self.cursor, attr)

Then, in the same file, change:

return base.CursorDebugWrapper(self.connection.cursor(), self)


return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self)

Attachments (1)

mysql.diff (1.6 KB) - added by mlambert@… 9 years ago.
unified diff file

Download all attachments as: .zip

Change History (4)

comment:1 Changed 9 years ago by mlambert@…

Oh wow the formatting on the above sucks.

Will upload a diff...

Changed 9 years ago by mlambert@…

unified diff file

comment:2 Changed 9 years ago by adrian

  • Status changed from new to assigned

comment:3 Changed 9 years ago by adrian

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

(In [806]) Fixed #473 -- Added a MysqlDebugWrapper to use for MySQL with DEBUG=True. It displays more informative error messages for MySQL warnings. Thanks for the patch, mlambert@…

Add Comment

Modify Ticket

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

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

Note: See TracTickets for help on using tickets.