Opened 6 years ago
Last modified 5 years ago
#45078 new defect (bug)
null is being set on a NOT NULL options_value column in the options table.
Reported by: | wpshades | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Options, Meta APIs | Keywords: | has-patch |
Focuses: | Cc: |
Description
The options
table doesn't allow a NULL value in the options_value
column.
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/schema.php#L144
But, if an option is unchecked, it is set to null by default here:
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/options.php#L275
This throws a Column ‘option_value’ cannot be null
error if strict mode(STRICT_TRANS_TABLES
) is enabled in the database.
If strict mode isn't enabled, MySQL converts the null value to a default value, in this case, an empty string, before adding it to the options
table.
If you are not using strict mode, then whenever you insert an “incorrect” value into a column, such as a NULL into a NOT NULL column or a too-large numeric value into a numeric column, MySQL sets the column to the “best possible value” instead of producing an error
https://dev.mysql.com/doc/refman/5.7/en/constraint-invalid-data.html
The proposed fix changes the default value from null to an empty string(following MySQL). This will prevent the error being thrown when strict mode is enabled and otherwise won't alter the values inserted into the option_value
column.
Set the default value of an unchecked option to empty string().