Bulk Edit causes deletion of array fields
Describe the Bug
It seems that with 3.0.0 and newer (I've tried up to 3.1.0 but I haven't tested older versions) when using bulk edit to update one field causes Payload to delete another field of type array.
Link to the code that reproduces this issue
https://github.com/thekiwi/payload-bulk-edit-bug
Reproduction Steps
-
Start the reproduction repo, pointing at a PostgreSQL database (I used 16.3)
-
Log into the Admin panel (first creating a user, if necessary)
-
Create a new Thing, leave 'enabled' unchecked, but add an entry to the 'foos' array
-
View the list of things, you should see
1 Foosfor the new thing -
Check the
things_fooscollection in the DB and observe there is now 1 record. -
Check the thing you just created and click "Edit" to start bulk editing
-
Toggle the 'enabled' field to true for the thing you just created
-
Click "Save"
-
Return to the list of things, you should see
0 Foosfor the thing you just edited -
Check the
things_fooscollection in the DB and observe there are now 0 records
Which area(s) are affected? (Select all that apply)
db-postgres, area: core
Environment Info
Binaries:
Node: 20.16.0
npm: 10.8.1
Yarn: 1.22.22
pnpm: 9.7.0
Relevant Packages:
payload: 3.1.0
next: 15.0.0
@payloadcms/db-postgres: 3.1.0
@payloadcms/email-nodemailer: 3.1.0
@payloadcms/graphql: 3.1.0
@payloadcms/next/utilities: 3.1.0
@payloadcms/payload-cloud: 3.1.0
@payloadcms/richtext-lexical: 3.1.0
@payloadcms/translations: 3.1.0
@payloadcms/ui/shared: 3.1.0
react: 19.0.0-rc-65a56d0e-20241020
react-dom: 19.0.0-rc-65a56d0e-20241020
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 8
I've reproduced this in the Payload monorepo pre 3.2 release using both db-postgres and db-mongodb. The odd thing is that it happens 4 / 5 times with the fifth time working as expected. Will double check if it's still happening.
i have a similar issue with bulk edit where fields with a defaultValue getting replaced to the set defaultValue https://github.com/payloadcms/payload/issues/9590
so far i also didnt get any comment on this
Hey @akhrarovsaid - did you get any further with this? It seems like a pretty critical bug, especially as @yonnic has pointed out it also affects fields with default values. We lost a whole lot of data before we realised what was actually going on.
@PatrikKozak I can see you've merged https://github.com/payloadcms/payload/pull/9842 - I'm assuming that PR fixes this issue as well?
Hey @thekiwi,
I tested this in the monorepo _community folder using your reproduction repo configuration and am no longer able to reproduce this issue! Bulk editting many docs leaves array fields untouched in my testing.
Hopefully this is out in the next release. I was considering authoring a PR for this one. However @PatrikKozak has, masterfully, managed to get 2 birds with 1 stone so to speak. Great job here.
Hey @thekiwi, @yonnic, @akhrarovsaid - Yup! My merged PR of #9842 will indeed fix the array issues as well! The original issue seems to have affected nested fields and fields with default values.
Tested for all of this in that PR.
We'll get a release out for this fix asap - going to close this for now.
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.