payload icon indicating copy to clipboard operation
payload copied to clipboard

Bulk Edit causes deletion of array fields

Open thekiwi opened this issue 1 year ago • 3 comments

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

  1. Start the reproduction repo, pointing at a PostgreSQL database (I used 16.3)

  2. Log into the Admin panel (first creating a user, if necessary)

  3. Create a new Thing, leave 'enabled' unchecked, but add an entry to the 'foos' array Image

  4. View the list of things, you should see 1 Foos for the new thingImage

  5. Check the things_foos collection in the DB and observe there is now 1 record. Image

  6. Check the thing you just created and click "Edit" to start bulk editingImage

  7. Toggle the 'enabled' field to true for the thing you just created Image

  8. Click "Save"

  9. Return to the list of things, you should see 0 Foos for the thing you just edited Image

  10. Check the things_foos collection in the DB and observe there are now 0 records Image

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

thekiwi avatar Nov 23 '24 23:11 thekiwi

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.

akhrarovsaid avatar Nov 28 '24 14:11 akhrarovsaid

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

yonnic avatar Dec 04 '24 20:12 yonnic

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.

thekiwi avatar Dec 05 '24 19:12 thekiwi

@PatrikKozak I can see you've merged https://github.com/payloadcms/payload/pull/9842 - I'm assuming that PR fixes this issue as well?

thekiwi avatar Dec 10 '24 19:12 thekiwi

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.

akhrarovsaid avatar Dec 10 '24 19:12 akhrarovsaid

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.

PatrikKozak avatar Dec 10 '24 19:12 PatrikKozak

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.

github-actions[bot] avatar Dec 12 '24 04:12 github-actions[bot]