-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility with Django 2.2 #790
Comments
Hi ncknuna, I believe you already tried modified the version by yourself and still having trouble. Here is why
Django 2.1.x used to cast every query into "str" like below Django 2.2.x they changed the code by using Could you also help open a ticket on Django's issue tracking system ? 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 |
@eavictor Ah, got it. Thanks so much for explaining! Issue filed here: https://code.djangoproject.com/ticket/30380 Just curious: if PyMySQL has compatibility with MySQLdb via install_as_MySQLdb(), which of PyMySQL and mysqlclient deviate from the MySQLdb interface here? |
@ncknuna Could you test if the error goes away with django/django#11259 made by felixxm ? |
I'm not currently blocked since I'm using mysqlclient in the meantime, so I don't think I'll get to this in a while, so if someone else wants to pick this up, that'd be great. Otherwise I'll try to poke at it when I get the chance! |
I will try squeeze some time this weekend upgrade django_backend_test repo and test if fix from Django works. |
Edit:
This can prevent opening same type of issues again in future. # __init__.py
from __future__ import print_function
import sys
...
version_info = (1, 3, 12, "final", 0)
...
def install_as_MySQLdb(MySQLdb_version=None):
"""
After this function is called, any application that imports MySQLdb or
_mysql will unwittingly actually use pymysql.
"""
if type(MySQLdb_version) == tuple and len(MySQLdb_version) == 5:
print("WARNING: Use at your own risk !!\nSet MySQLdb version = {}".format(MySQLdb_version))
global version_info
version_info = MySQLdb_version
sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"] Default behavior of >>> import pymysql
>>> pymysql.install_as_MySQLdb()
>>> pymysql.version_info
(1, 3, 12, 'final', 0)
>>> Passing extra argument: >>> import pymysql
>>> pymysql.install_as_MySQLdb(MySQLdb_version=(1, 4, 2, "final", 0))
WARNING: Use at your own risk !!
Set MySQLdb version = (1, 4, 2, 'final', 0)
>>> pymysql.version_info
(1, 4, 2, 'final', 0)
>>> |
@eavictor Thanks for your testing. |
This looks like it will be addressed in the Django 3.0 release which is slated for December 2, 2019. |
@mcrowson I went to that page but wasn't able to find anything related to this - any chance you could point to the update you were talking about? |
Django 3.0 has been out there already. However, pymysql is still not working with django==3.0. $ pip freeze | grep -Ei "(django)|(pymysql)"
Django==3.0
django-braces==1.13.0
django-filter==2.2.0
django-rest-framework-social-oauth2==1.1.0
djangorestframework==3.10.3
djangorestframework-filters==1.0.0.dev0
PyMySQL==0.9.3
$ python manage.py shell
...
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
|
Hello @ace-han Please read the reply from methane at May/06/2019. import pymysql
pymysql.version_info = (1, 4, 6, 'final', 0) # change mysqlclient version
pymysql.pymysql.install_as_MySQLdb() |
I can confirm that adding these lines to your settings.py (at the beginning of the database section) works in Django 3.0. No need to do any of the other mysterious craft mentioned previously in the thread. import pymysql
pymysql.version_info = (1, 4, 6, 'final', 0) # change mysqlclient version
pymysql.pymysql.install_as_MySQLdb() |
Thank you, but what "I can confirm" means? |
I meant that I tried it and it worked. I did not run the Django testsuite. I was getting the error mentioned in this thread when trying to run my app with Django 2.2 or later and PyMySQL. So, I modified the settings.py file of my Django app to change the mysqlclient version, and it runs properly now. |
PyMySQL doesn't work (afaik) in Django 2.2 because the byte handling patches mentioned earlier in the thread weren't backported. However, it seems to work fine in Django 3.0 after setting |
This helped me,thanks |
should be
|
This is basically identical to #610, but for a newer Django version.
Django recently bumped the required mysqlclient version to 1.3.13 (django/django@88619e6), but pymysql's version string only says it's only compatible with 1.3.12 (#623)
Any way we can get at least 1.3.13 support? Like the reporter of that other issue, I don't really know the implications of this change, and I can just make mysqlclient work in the interm, but I do prefer pymysql for ease of use on mac. Thanks so much for all your work supporting this library! :)
The text was updated successfully, but these errors were encountered: