#473 closed enhancement (fixed)
Make MySQL warnings more informative
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
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: | no | UI/UX: | no |
Description
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/mysql.py, add the following class:
class MysqlDebugWrapper:
def init(self, cursor):
self.cursor = cursor
def execute(self, sql, params=[]):
try:
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):
try:
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]
else:
return getattr(self.cursor, attr)
Then, in the same file, change:
return base.CursorDebugWrapper(self.connection.cursor(), self)
to:
return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self)
Attachments (1)
Change History (4)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Status: | new → assigned |
---|
comment:3 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Oh wow the formatting on the above sucks.
Will upload a diff...