api-platform / admin

A beautiful and fully-featured administration interface builder for hypermedia APIs
https://api-platform.com/docs/admin/
MIT License
480 stars 130 forks source link

Error on update entity with self reference. #502

Closed KDederichs closed 1 year ago

KDederichs commented 1 year ago

API Platform version(s) affected: 3.1.x

Description

Honestly I'm a bit stumped on that one since I can't for the life of me find what's causing it but:

If you have an entity that self references (a user referring another user for example) and you then create an edit form with a ReferenceInput that has an AutoCompleteInput as child it'll throw an error when you try to update the entity AND the reference input is empty.

It'll then it you with this:

Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')
    at onSuccess (useGetManyAggregate.js?d6f3:119:1)
    at eval (notifyManager.js?eb8e:62:1)
    at NotifyManager.notifyFn (notifyManager.js?eb8e:10:1)
    at eval (notifyManager.js?eb8e:77:1)
    at Array.forEach (<anonymous>)
    at eval (notifyManager.js?eb8e:76:1)
    at NotifyManager.batchedUpdates$1 [as batchNotifyFn] (react-dom.development.js?03cb:26140:1)
    at eval (notifyManager.js?eb8e:75:1)

Which is caused by onSuccess in useGetManyAggregate receiving undefined.

The crux here is though: As far as I can tell that query should be disabled in the first place.

I honestly have no clue what the heck is causing this or whether you or the folks at the react-admin repo are causing this (already got a ticket there as well https://github.com/marmelab/react-admin/issues/8684) but yeah...

How to reproduce
1) Execute this reproducer (docker compose up -d): https://github.com/KDederichs/demo/tree/reproducer/update_error 2) Go to the reviews admin 3) Edit any of them, doesn't matter 4) Change something, but leave the selfRef field empty. 5) Click Save 6) See Error

KDederichs commented 1 year ago

Seems like the bug was on their end after all and is getting fixed there, so I'll go ahead and close this.