WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 11 months 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:
PR Number:

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.

Attachments (1)

0001.diff (395 bytes) - added by wpshades 14 months ago.
Set the default value of an unchecked option to empty string().

Download all attachments as: .zip

Change History (3)

@wpshades
14 months ago

Set the default value of an unchecked option to empty string().

#1 @wpshades
14 months ago

Another thing that I wanted to note was if safe mode is turned on and we turn off any options under wp-admin->Settings they are automatically turned back on as the update_option() fails and returns false.

#2 @pento
11 months ago

  • Component changed from Database to Options, Meta APIs
  • Version trunk deleted
Note: See TracTickets for help on using tickets.