Opened 6 years ago

Closed 6 years ago

#10851 closed (duplicate)

mysql CursorWrapper.execute has different prototype than CursorDebugWrapper

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

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 wdoekes 6 years ago.
replace args=None with params=() in MySQL CursorWrapper

Download all attachments as: .zip

Change History (2)

Changed 6 years ago by wdoekes

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

comment:1 Changed 6 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

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

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