payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
27.76k stars 1.72k forks source link

Deleted media that included in upload field hasMany, showing undefined id in admin panel #9328

Open henrytrianta opened 3 days ago

henrytrianta commented 3 days ago

Describe the Bug

When an item media deleted from collection, that is already linked to upload field with an option hasMany: true, causing error: Cannot read properties of undefined (reading 'id').

@paulpopus

Link to the code that reproduces this issue

https://github.com/henrytrianta/payload-reproduce-has-many-issue

Reproduction Steps

  1. Create an item in collection posts
  2. Upload multiple images to post
  3. Go to Media and delete one of the image
  4. Go back to post that have the images that is already linked in but deleted
  5. There is an error saying: Cannot read properties of undefined (reading 'id').

Which area(s) are affected? (Select all that apply)

area: core, Not sure

Environment Info

Binaries:
  Node: 22.9.0
  npm: 10.8.3
  Yarn: 1.22.22
  pnpm: 9.11.0
Relevant Packages:
  payload: 3.0.0
  next: 15.0.0
  @payloadcms/db-mongodb: 3.0.0
  @payloadcms/email-nodemailer: 3.0.0
  @payloadcms/graphql: 3.0.0
  @payloadcms/next/utilities: 3.0.0
  @payloadcms/payload-cloud: 3.0.0
  @payloadcms/richtext-lexical: 3.0.0
  @payloadcms/translations: 3.0.0
  @payloadcms/ui/shared: 3.0.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.1.0: Thu Oct 10 21:02:45 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8112
  Available memory (MB): 8192
  Available CPU cores: 8
poofy25 commented 2 days ago

i am also facing the same issue

akhrarovsaid commented 10 hours ago

Yep, I've reproduced your issue. Many ways to handle this honestly, I pursued the one that made the most sense to me from an editors pov. PR is here.