-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #24018 -- Allowed setting pragma options on SQLite. #14824
Conversation
Hello @linville! Thank you for your contribution 💪 As it's your first contribution be sure to check out the patch review checklist. If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket! If you have any design or process questions then you can ask in the Django forum. Welcome aboard ⛵️! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@linville Thanks for the patch 👍 I can see one issue with this approach, we don't inform users when sth goes wrong.
Thanks for reviewing! Could you expand on "when sth goes wrong", not sure I'm following? Would this be if the user uses invalid pragma/syntax in the |
As in the ticket description, See also Carlton's comment. |
Looking at the MySQL backend behavior for Thinking about approaches for this: whether a value is returned from a pragma statement varies on the pragma, some will return a value (e.g.: If we'd like to do validation, I'd be happy to take a shot at an implementation of the above approach if it seems reasonable. |
I'm not sure we'd need to validate the result of the |
I think validating every statement in the If we do want validation, then I think a better approach would be to expose the pragma settings that we want to support and validate through DATABASE OPTIONS e.g. To me personally either approach works, I'd just really like to have this feature land in 5.1! Happy to help out in any way I can to get this done. |
@linville Thanks for updates 👍 I left small suggestions. |
Great work thanks! Would it be possible/make sense to set or recommend (in docs) a "sensible default configuration" for using SQLite in the context of a web app? Ruby on Rails being very opinionated, decided to set some defaults. To me this makes a lot sense since this is mostly the configuration I'm using in my web projects. The only thing missing is setting the DEFAULT_PRAGMAS = {
"foreign_keys" => true,
"journal_mode" => :wal,
"synchronous" => :normal,
"mmap_size" => 134217728, # 128 megabytes
"journal_size_limit" => 67108864, # 64 megabytes
"cache_size" => 2000
} Here's a link to the RoR settings for SQLite and here's a great blog post that helps understand the configuration and performs some benchmarks. |
I don't think so. If we decided we needed more options we would set them automatically, as we already do: django/django/db/backends/sqlite3/base.py Lines 200 to 203 in c991602
You can start a discussion on the Django Forum if you strongly believe that Django should set more options by default. |
Thank you for the review! I believe (hope!) I've got the requested changes incorporated now. |
tests/backends/sqlite/tests.py
Outdated
"ENGINE": "django.db.backends.sqlite3", | ||
"NAME": ":memory:", | ||
"OPTIONS": { | ||
"init_command": "PRAGMA synchronous=3;", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that it won't work for multiple PRAGMA statements:
sqlite3.Warning: You can only execute one statement at a time.
I think we should change it to the list. It's probably better for consistency with MySQL options to split this on ;
.
@linville Thanks 👍 Welcome aboard ⛵ |
Adds support to the SQLite backend for the
init_command
option so user can set PRAGMA options when setting up the connection.SQLite doesn't natively support the
init_command
keyword (such as MySQL does), the command is just run right after the connection is established.Ticket #24018 in Trac