Closed skwigs closed 9 months ago
There is already an issue open on this. https://github.com/supabase/postgrest-js/issues/405
@GaryAustin1 Please note this issue provides more detail for troubleshooting than https://github.com/supabase/postgrest-js/issues/405 It details how the root cause of the behavior is the underlying REST API call itself and not just the JS library. It also shows the recommended workaround of returning the inserted/updated object is also impacted by the same error.
I moved this over to Postgrest-js issues so it stays close to the other.
Sounds good. I just wanted to make sure there was awareness as I didn't say which API in my title before. Just fixed that. Thanks!
Bug report
Describe the bug
Success messages are not returned in the body of Rest API responses (e.g., insert, update). The 201 success HTTP response is captured, but the body is completely empty even when looking at it in raw.
The problem is the success message is being returned in the error attribute of the response. Since "returned_an_error" is false, you never see the success message.
Note: The object in the "error" attribute (above) is the same response the JS docs v2.0 say should be returned when the call is successful (below).
Workaround (and it's issues)
The workaround appears to be to "Create a record and return it". In the discussion threads, much has been said about appending .select() to your JS function as shown here. In the API, you can set the Prefer header to return=representation.
However, the response is again not the same as expected per the JS 2.0 docs. Only the data array is returned...
...and the status text continues to be in an error attribute outside the body and headers.
Reading the discussion threads some people have said responses worked properly in v1 and then changed in v2. There's an assumption this was intentional, but it seems more like a bug given:
Also, it's interesting that the Rest API is still v1, and so you'd expect it behave as it did before the upgrade. So again, this shouldn't be a case of v1 versus v2 functionality. It seems more like the success messages just aren't getting routed to the correct place in the response now.
To Reproduce
This issue was particularly difficult to track down because of how Postman and other tools like it parse API responses. I happened to be integrating Supabase with bubble.io, and their response handling allows you to see error data even when an error is not thrown.
Steps to reproduce:
Congrats. You're call settings should now look something like this.
Additional context
Since bubble requires you to initialize your APIs with a successful call, this issue kept me from integrating bubble and Supabase for along time. Checking the boxes to show errors seems to get around this constraint, but it took a long time figure out what was going on with no response object coming back form Supabase via Postman either. I'm not the only one who has experience this though as several others have run into the empty response issue as well and I'm sure the mods are tired of responding to it.
Finally, the fix to this bug could result in client impact as it may be a breaking change. For example, if the Rest API is updated to match the docs, then apps using the workaround of getting a representation object will need to be updated to access the Data property first before getting to the array with their data in it. Might be worth it to make sure there's good communication if/when a fix for this is released.