#22391 closed New feature (wontfix)

fallback to pymysql if MySQLdb not available

Reported by: CollinAnderson 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 18 months ago by CollinAnderson

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 18 months ago by loic84

  • Triage Stage changed from Unreviewed to 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:3 Changed 18 months ago by aaugustin

Related: #12500.

comment:4 Changed 18 months ago by anonymous

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 Changed 18 months ago by CollinAnderson

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 18 months ago by CollinAnderson

My "fix dates before 1900" change just merged. https://github.com/PyMySQL/PyMySQL/pull/232

comment:7 Changed 16 months ago by timo

  • 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 14 months ago by CollinAnderson

  • Cc cmawebsite@… added

comment:10 Changed 14 months ago by akaariai

  • 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 14 months ago by akaariai (previous) (diff)

comment:11 Changed 14 months ago by collinanderson

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 Changed 11 months ago by timgraham

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

comment:13 Changed 11 months ago by collinanderson

  • Resolution set to wontfix
  • Status changed from new to closed

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