Opened 4 years ago

Closed 4 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: master
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


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:

        import pymysql
    except ImportError:

I think it would help python 3 adoption if users could use django and pymysql without additional steps.

Change History (13)

comment:1 Changed 4 years ago by Collin Anderson

Has patch: set

comment:2 Changed 4 years ago by loic84

Triage Stage: UnreviewedAccepted

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:3 Changed 4 years ago by Aymeric Augustin

Related: #12500.

comment:4 Changed 4 years ago by anonymous

I have also a dedicated branch for this: However, I think the test suite does not entirely pass with that patch.

comment:5 Changed 4 years ago by Collin Anderson

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 Changed 4 years ago by Collin Anderson

My "fix dates before 1900" change just merged.

comment:7 Changed 4 years ago by Tim Graham

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:9 Changed 4 years ago by Collin Anderson

Cc: cmawebsite@… added

comment:10 Changed 4 years ago by Anssi Kääriäinen

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.

Last edited 4 years ago by Anssi Kääriäinen (previous) (diff)

comment:11 Changed 4 years ago by Collin Anderson

Sorry, I should link to the django-developers ghost-thread, and maybe bump it.

comment:12 Changed 4 years ago by Tim Graham

Do we still need this now that we have support for mysqlclient (with no changes to Django)?

comment:13 Changed 4 years ago by Collin Anderson

Resolution: wontfix
Status: newclosed

I think I'm fine with closing for now, though I still think pymysql is quite popular due to it being pure python.

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