raphiniert-com / ra-data-postgrest

react admin client for postgREST
MIT License
106 stars 34 forks source link

Update fails when nothing is changed #141

Closed copierrj closed 4 days ago

copierrj commented 2 months ago

When manipulating multiple related resources in a single form (using ReferenceManyInput, ReferenceOneInput, etc.) the update function of the data provider gets called for every resource. When no fields of a particular resource are changed update gets called with the same value for 'data' and 'previousData'.

Because ra-data-postgrest only updates changed fields, a PATCH request with an empty object ({}) is send to PostgREST resulting in an error:

{
     "code":"PGRST116",
     "details":"The result contains 0 rows",
     "hint":null,
     "message":"JSON object requested, multiple (or no) rows returned"
}
scheiblr commented 2 months ago

Thank you for reporting the issue. Do you have any minimal example somewhere?

copierrj commented 2 months ago

I've created a small example project: https://github.com/copierrj/react-admin-test

A docker-compose for the backend (PostgreSQL + PostgREST) used by this project can be found here: https://github.com/copierrj/pagila/tree/postgrest

The problem is demonstrated in this form: https://github.com/copierrj/react-admin-test/blob/4161ffeb0c76dff5048156e5ae3f8dcf5b7175d6/src/CustomerEdit.tsx#L23-L37

Editing address details (stored in resource address) without editing other customer information (stored in resource customer) triggers the bug.

kav commented 1 month ago

I have a few places I've run into this, one recently is many to many inputs trigger an empty patch on the edited resource