#30380: Support mysql query objects as strings in addition to bytes, for PyMySQL
support
-----------------------------------------+------------------------
Reporter: Nathan Klug | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Per https://github.com/PyMySQL/PyMySQL/issues/790, Django 2.2 changed the
expected type of mysql queries; it's be great if we could support both
mysqlclient and PyMySQL here. More details from that issue:
Django 2.1.x used to cast every query into "str" like below
https://github.com/django/django/blob/stable/2.1.x/django/db/backends/mysql/operations.py#L134
Django 2.2.x they changed the code by using query.decode instead of
force_text method.
https://github.com/django/django/blob/stable/2.2.x/django/db/backends/mysql/operations.py#L140
Could you also help open a ticket on Django's issue tracking system ?
It's relatively easy to fix from Django side.
e.g.
{{{
from django.utils.encoding import force_text
def last_executed_query(self, cursor, sql, params):
# With MySQLdb, cursor objects have an (undocumented) "_executed"
# attribute where the exact query sent to the database is saved.
# See MySQLdb/cursors.py in the source distribution.
query = getattr(cursor, '_executed', None)
if query is not None:
if type(query) == bytes:
query = query.decode(errors='replace') # mysqlclient
elif type(query) == str:
query = query.encode(errors='replace') # PyMySQL
else:
query = force_text(query, errors='replace') # fallback
compatibility ?
return query
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30380>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.7877a625500e710415da95261d36b211%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.