craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 626 forks source link

[4.x]: Some checkboxes are pre-checked after updating from 4.4.17 to 4.5.5 #13710

Closed Mixxey closed 11 months ago

Mixxey commented 12 months ago

What happened?

Description

After updating from Craft 4.4.17 to 4.5.5 several checkboxes used to control styling options and sometimes other functions are checked across several entries which were not checked before the update and are not meant to be checked in their specific contexts.

This happens independent of the entry and field types they are attached to. I found the checked checkboxes in constructions as complex as "a matrix field inside of a neo block inside of a neo block" but also in checkboxes on entry-level so it doesn't seem to have something to do with neo blocks or the overall complexity.

I also noticed that all affected checkbox-type fields didn't have the "Die Feldwerte als Suchschlüsselwörter verwenden"-checkbox checked (the one just above the dropdown where you set the field type), but checking those before the update didn't prevent the error.

Sadly, I wasn't able to find out more on my own, but maybe you can help? Many thanks in advance for looking into this mystery :)

Steps to reproduce

  1. Update from Craft 4.4.17 to 4.5.5

Expected behavior

No additional checkboxes should be checked that aren't meant to be checked.

Actual behavior

Checkboxes are checked without any too obvious pattern: Sometimes all occurrences within an entry are affected, sometimes only specific ones; some entries don't seem to be affected at all.

Craft CMS version

Craft Pro 4.5.5

PHP version

8.0.30

Operating system and version

Linux 6.2.0-32-generic

Database type and version

MySQL 5.7.43

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.10-23)

Installed plugins and versions

i-just commented 12 months ago

Hi, thanks for reaching out. Any chance you could please send your composer.json, composer.lock and database export from before the update to support@craftcms.com and point to a few entries that are affected by this issue?

Mixxey commented 12 months ago

Hi Iwona, thanks for getting back to me! I just sent an email with the provided info via WeTransfer (to have room for the database export). I hope this worked and helps :)

i-just commented 12 months ago

Hi Tina, thanks for the files!

Replication steps:

  1. create an entry
  2. once the entry is saved, create a new checkbox field; keep the default empty row under “Checkbox Options” (the value has to be blank)
  3. add that field to the entry type for the entry you created in the first step
  4. edit the entry from the first step - the checkbox shows as checked

This will happen in the 4.5+ versions (you don’t have to go through the update process to replicate it).

This is a side effect of the field value being NULL in the database (because the field was added to the entry type, but the entry hasn’t been saved since) and an empty string ('') option available in the checkbox field (in this case, if the checkbox is not selected, the value for this field is stored in the DB as an empty array []; if the checkbox is selected, the value for this field is stored in the DB as an array with an empty string in it [""]).

I’m working on a PR to adjust this behaviour.

Mixxey commented 12 months ago

Hi Iwona, thanks a lot, this is really interesting! I'm lookin forward to hearing from you again. Thank you for the very quick and good support! :)

brandonkelly commented 11 months ago

This is now fixed for the next release, via #13727 🎉

brandonkelly commented 11 months ago

Craft 4.5.6 is out now with that fix.

Mixxey commented 11 months ago

Great! Thanks so much :)