-
Notifications
You must be signed in to change notification settings - Fork 94
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
Errors when updating options (SQLSTATE[23000]: Integrity constraint violation) #18
Comments
As a quick fix/test I tried to filter new option values and change
But it still does look very fragile to me. Also, this may still happen in other tables (from reading debug.txt, at least on @aaemnnosttv Is this a known issue or something that happens only to me? I like the portability of a file-only, lightweight WordPress powered by SQLite, but this issue may bring some serious side effects. Thanks. |
I haven't seen this before but I was able to reproduce what you're seeing. I'm not really sure what's going on because WP sets those to Will look into this more soon. |
Looking further, it looks like WordPress explicit set the (unchecked) option values to https://github.com/WordPress/WordPress/blob/master/wp-admin/options.php#L306 But I don't know why this doesn't trigger the same error with MySQL. I tried to set At the same time, random people seems to experience this even on MySQL: https://www.reddit.com/r/Wordpress/comments/l61rvs/cannot_disable_avatars/ But yes, this looks like something related with WordPress itself. Nevertheless, executing something like |
Ok, this has taken more time than expected but, for completeness, the reason why this does not fail with MySQL is that WordPress explicitly disable any strict mode by default, and without it, MySQL silently "fix" any incorrect values: https://github.com/WordPress/WordPress/blob/f0078d043e0f2805c2400bd5e869eb3533712eec/wp-includes/wp-db.php#L567 All of this of course has no effect on this SQLite implementation. While this should be fixed in WordPress core, I don't know how easily or even if it would be a good idea to patch At least, my previous fix seems to fix this issue but should be installed as a separate plugin or included in a theme functions.php, for now. Thanks. |
Was there any update on this? I ran into this issue just today, is there a Wordpress issue to track? Or any reccommended workarounds? |
At the time I submitted a PR but went unnoticed: WordPress/wordpress-develop#1074 The simple filter inside the trac ticket or at the top of this thread should fix most of the issues, though. |
Got it, thanks for the update! I'm not super familiar with Wordpress scripts/plugins, how would you recommend I use that filter? Do I just put it inside of my wordpress config PHP file, or should it go somewhere else? |
Simplest fix in the my db.php: (for PHP 7.4+) // replace NULL to ''
add_filter('pre_update_option', fn($val) => $val ?? '');
// include original dropin
include __DIR__ . '/dropins/wp-sqlite-db/src/db.php'; |
It looks like there are errors when you try to save some options on the backend.
From what I can see, schema for
option_value
isTEXT NOT NULL
but the query executed try to set value toNULL
.Steps to reproduce: In the backend, go to Settings -> Discussion, deselect any option and try to save.
Wordpress Debug Output:
debug.txt:
WordPress version: 5.6.2
PHP version: 7.4
Note: When
WP_DEBUG
is set tofalse
it just fails to update the options silently.The text was updated successfully, but these errors were encountered: