Opened 15 years ago

Closed 15 years ago

#10851 closed (duplicate)

mysql CursorWrapper.execute has different prototype than CursorDebugWrapper

Reported by: Walter Doekes Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: walter@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

/usr/share/python-support/python-django/django/db/backends/mysql/base.py:
class CursorWrapper(object):
    def execute(self, query, args=None):
    def executemany(self, query, args):
/usr/share/python-support/python-django/django/db/backends/sqlite3/base.py:
class SQLiteCursorWrapper(Database.Cursor):
    def execute(self, query, params=()):
    def executemany(self, query, param_list):
/usr/share/python-support/python-django/django/db/backends/postgresql/base.py:
class UnicodeCursorWrapper(object):
    def execute(self, sql, params=()):
    def executemany(self, sql, param_list):
/usr/share/python-support/python-django/django/db/backends/util.py:
class CursorDebugWrapper(object):
    def execute(self, sql, params=()):
    def executemany(self, sql, param_list):

If you're in DEBUG-mode, you get the DebugWrapper and an empty tuple as default parameter. For queries without parameters this means that you have to escape percent signs (using the double-percent).

When you switch to !DEBUG, you get the regular CursorWrapper that gets a None as default. Now parameter-less queries do not want the percent-sign escaped.

The fix: change

    def execute(self, query, args=None):

to

    def execute(self, query, args=()):

in /usr/share/python-support/python-django/django/db/backends/mysql/base.py

Regards,
Walter Doekes
OSSO B.V.

Attachments (1)

mysql_default_params_tuple.diff (1.2 KB ) - added by Walter Doekes 15 years ago.
replace args=None with params=() in MySQL CursorWrapper

Download all attachments as: .zip

Change History (2)

by Walter Doekes, 15 years ago

replace args=None with params=() in MySQL CursorWrapper

comment:1 by Karen Tracey, 15 years ago

Resolution: duplicate
Status: newclosed

#9055 is already open for this and covers all backends, not just MySQL.

Note: See TracTickets for help on using tickets.
Back to Top