Loading SQLite extensions (such as SpatiaLite?, which happens to be my use case) requires pysqlite 2.5.0, which is newer than the version that now ships as the sqlite3 module with Python. Currently Django always uses sqlite3 if it is present, even if the user has installed a newer version of pysqlite2.
The original reason for making sqlite3 the default was to “to do the right thing first and fallback” (#2772), which made the (seemingly reasonable) assumption that sqlite3 would become the undisputed correct name in the future. Unfortunately the package itself retained the pysqlite2 name, and only the Python-internal snapshots (which will inevitably become outdated) have the sqlite3 name.
So the question is, how can users take advantage of newer versions of pysqlite2, without having to go mucking around in their Python installation to disable the older sqlite3 module (or something equally unpleasant).
Options include:
A. Leave sqlite3 as the default, and add a configuration setting that forces use of pysqlite2 if desired.
B. Always try both sqlite3 and pysqlite2, and use whichever has the greater version number if both are present.
C. Same as B, but with an optional configuration option to force one or the other if desired.
D. Switch to making pysqlite2 the default, since that’s the correct name for the module if the user has explicitly installed it, and treat the Python-bundled version as the fallback.
E. Develop arbitrarily convoluted bits of logic that pay attention to e.g. what Python version we're running under or the phase of the moon or something.
Several of these seem like reasonable options. For the moment I have created a simple patch that implements option B. I'm curious what others think about this.
It's not at all obvious to me how to write tests for a patch like this, since shouldn’t change the behavior in any way unless you happen to have a new version of pysqlite2 installed on your system. So, for the moment I have no tests. I would love some advice on what, if any, tests I could add.