#411 closed defect (fixed)
CursorDebugWrapper does not support pyformat paramstyle.
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | trivial | 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
According to the Python Database API Specification v2.0, the paramters provided to the cursor.execute() method can be sequences or mappings.
http://www.python.org/peps/pep-0249.html
Right now, the CursorDebugWrapper is converting all params to tuples before appending it to the queries list. This is causing my calls that use the pyformat paramstyle to fail during DEBUG mode. Below I removed the 'tuple()' function call which fixes my error. Of course, if there is a reason for this explicit conversion to tuple type that I do not see then a better work around would be needed.
class CursorDebugWrapper: def __init__(self, cursor, db): self.cursor = cursor self.db = db def execute(self, sql, params=[]): start = time() result = self.cursor.execute(sql, params) stop = time() self.db.queries.append({ 'sql': sql % params, 'time': "%.3f" % (stop - start), }) return result
Change History (4)
comment:1 by , 19 years ago
Component: | Admin interface → Database wrapper |
---|
comment:2 by , 19 years ago
comment:3 by , 19 years ago
what I did was:
def execute(self, sql, params=()): start = time() try: return self.cursor.execute(sql, params) finally: if not isinstance(params, (tuple, dict)): params = tuple(params) stop = time() self.db.queries.append({ 'sql': sql % params, 'time': "%.3f" % (stop - start), })
comment:4 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
The tuple function is needed for lists of 1 item. Below is a very simple-mided check for DictType which I think is acceptable.