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 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).
- Leave sqlite3 as the default, and add a configuration setting that forces use of pysqlite2 if desired.
- Always try both sqlite3 and 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 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.
- 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)
Changed 7 years ago by mdh
comment:1 Changed 7 years ago by mrts
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 7 years ago by mrts
- Needs documentation set
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Design decision needed
comment:4 Changed 7 years ago by jbronn
- milestone set to 1.1
- Owner changed from nobody to jbronn
- Status changed from new to assigned
- Triage Stage changed from Design decision needed to Accepted
comment:5 Changed 7 years ago by jbronn
- Resolution set to fixed
- Status changed from assigned to closed