Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fails when nothing is changed #141

Closed
copierrj opened this issue Jun 19, 2024 · 3 comments · Fixed by #166
Closed

Update fails when nothing is changed #141

copierrj opened this issue Jun 19, 2024 · 3 comments · Fixed by #166
Labels
bug Something isn't working

Comments

@copierrj
Copy link

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
Copy link
Collaborator

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

@copierrj
Copy link
Author

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.

@scheiblr scheiblr added the bug Something isn't working label Jul 3, 2024
@kav
Copy link
Contributor

kav commented Jul 30, 2024

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

fzaninotto added a commit to fzaninotto/ra-data-postgrest that referenced this issue Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants