Using pysqlite2 instead of sqlite3 when needed
|Reported by:||mdh||Owned by:||jbronn|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||no||Patch needs improvement:||no|
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
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
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).
sqlite3as the default, and add a configuration setting that forces use of
- Always try both
pysqlite2, and use whichever has the greater version number if both are present.
- Same as B, but with an optional configuration option to force one or the other if desired.
- Switch to making
pysqlite2the 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.
- 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.
Change History (10)
comment:1 Changed 8 years ago by
|Patch needs improvement:||unset|
comment:2 Changed 8 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Unreviewed → Design decision needed|
comment:4 Changed 8 years ago by
|Owner:||changed from nobody to jbronn|
|Status:||new → assigned|
|Triage Stage:||Design decision needed → Accepted|