#9628 closed (fixed)
Using pysqlite2 instead of sqlite3 when needed
Reported by: | mdh | Owned by: | jbronn |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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:
- Leave
sqlite3
as the default, and add a configuration setting that forces use ofpysqlite2
if desired.
- Always try both
sqlite3
andpysqlite2
, 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.
Attachments (4)
Change History (10)
by , 16 years ago
Attachment: | use-pysqlite2-if-newer.diff added |
---|
by , 16 years ago
Attachment: | 9628-r9781.diff added |
---|
Another attempt at a patch for this that attampts to: Be more correct (no undefined exc, e1 vars), simpler, and appying what I learned from #8193
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Needs documentation: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Design decision needed |
by , 16 years ago
Attachment: | 9628-r9791-optionD.diff added |
---|
Patch implementing strategy D as per django-dev thread
by , 16 years ago
Attachment: | 9628-r9791-optionA.diff added |
---|
Patch implementing strategy A as per django-dev discussion
comment:3 by , 16 years ago
Patch needs improvement: | unset |
---|
I've attached two patches implementing both options D and A (in the last case the name choosen for the relevant setting.DATABASE_OPTIONS dictionary key is 'module').
If/when one of the patches is deemed correct, will add the needed documentation modifications.
comment:4 by , 16 years ago
milestone: | → 1.1 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Triage Stage: | Design decision needed → Accepted |
comment:5 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
A first patch to use whichever of sqlite3 and pysqlite2 is newer.