Opened 11 years ago
Closed 10 years ago
#22391 closed New feature (wontfix)
fallback to pymysql if MySQLdb not available
Reported by: | Collin Anderson | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | cmawebsite@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Currently, pymysql is the best-supported mysql adapter on python 3. However, users need to use the following trick to get it to work with django:
try: import pymysql pymysql.install_as_MySQLdb() except ImportError: pass
I think it would help python 3 adoption if users could use django and pymysql without additional steps.
Change History (13)
comment:1 by , 11 years ago
Has patch: | set |
---|
comment:2 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
I agree it'd be nice to have support for pymysql, and I actually worked on it a little while ago before giving up.
I don't think a fallback mechanism is the right approach though, I'd much prefer a minimal yet separate db backend that'd leverage most of the implementation of the default backend.
Did you manage to get the test suite to work with this patch? I remember running into a lot of issues when I tried.
comment:4 by , 11 years ago
I have also a dedicated branch for this: https://github.com/claudep/django/tree/pymysql. However, I think the test suite does not entirely pass with that patch.
comment:5 by , 11 years ago
It looks like testing against the latest version of pymysql, 0.6.1 (October 2013), there are some errors, but, using pymysql's master branch, there are at least fewer errors. Some recent things that have been fixed are Thing2Literal and query encoding. I also have a pull request in to fix dates before 1900. It looks like there's a ticket open for timezone support.
It seems to me we should try to fix pymysql as much as possible to try to get it compatible with MySQLdb, and then require the latest version of pymysql.
Also, I'm personally interested in also using pymysql on python2.7, so I would prefer the fallback approach myself. Though, it's clear the real benefit of this is for python 3.
comment:6 by , 11 years ago
My "fix dates before 1900" change just merged. https://github.com/PyMySQL/PyMySQL/pull/232
comment:7 by , 11 years ago
Patch needs improvement: | set |
---|
Maybe this needs discussion on the mailing list for a resolution. One question I have is how we are going to ensure that it doesn't break if we merge it to core. Do we need another MySQL build to the Jenkins matrix?
comment:8 by , 11 years ago
Patch needs improvement: | unset |
---|
My branch merges cleanly again.
https://github.com/django/django/pull/2520#issuecomment-45358916
https://github.com/collinanderson/django/compare/ticket_22391
comment:9 by , 10 years ago
Cc: | added |
---|
comment:10 by , 10 years ago
Patch needs improvement: | set |
---|
If I understand correctly we at least need CI support for testing pymysql builds? Are there still errors when using pymysql or is this otherwise ready for merge?
The best way forward is to ask for CI support for pymysql builds on django-developers mailing list. If there are errors that can't be fixed on pymysql and if they are esoteric corner cases then we could consider skipping those tests on pymysql.
I'll set patch needs improvement for lack of better marker that this ticket isn't ready for merge.
comment:11 by , 10 years ago
Sorry, I should link to the django-developers ghost-thread, and maybe bump it. https://groups.google.com/d/topic/django-developers/n-TI8mBcegE/discussion
comment:12 by , 10 years ago
Do we still need this now that we have support for mysqlclient (with no changes to Django)?
comment:13 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I think I'm fine with closing for now, though I still think pymysql is quite popular due to it being pure python.
https://github.com/django/django/pull/2520