Skip to content

Updating data returns an empty Exception when there is no results returned #87

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

Closed
osaxma opened this issue Jan 19, 2022 · 4 comments
Closed
Labels
bug Something isn't working postgrest This issue or pull request is related to postgrest

Comments

@osaxma
Copy link

osaxma commented Jan 19, 2022

Take the following function as an example:

  @override
  Future<void> markNotificationsAsSeen() async {
    final res = await supabaseClient
        .from('notifications')
        .update({'is_seen': true}, returning: ReturningOption.minimal)
        .eq('notified_uid', supabaseClient.auth.currentUser!.id)
        .eq('is_seen', false) // <~~~ commenting this out makes the error disappear
        .execute();
    if (res.hasError) {
      throw Exception(res.error);
    }
  }

When all notifications for the given notified_uid are already false (i.e. no result is returned), I get the following exception:

Exception: PostgrestError(message: [], code: null, details: null, hint: null)

I was able to confirm this in several ways:

  • commenting out .eq('is_seen', false) -- no issue
  • Manually changing a single notification's is_seen to false on Dashboard -- no issue on the first call, error appears in subsequent ones.
  • I ran the query on the Dashboard -- no issues.

Given that, I assume the error is caused when no results are returned.

Version:

  • supabase: ^0.2.13
  • flutter: 2.8.1
@bdlukaa bdlukaa added the bug Something isn't working label Jan 19, 2022
@bdlukaa bdlukaa transferred this issue from supabase/supabase-dart Apr 17, 2022
@bdlukaa bdlukaa added the postgrest This issue or pull request is related to postgrest label Apr 17, 2022
@bdlukaa
Copy link
Collaborator

bdlukaa commented Jul 16, 2022

Looks like an issue with returning: ReturningOption.minimal

@dshukertjr
Copy link
Member

The library now throws 404 error with message of not found now, which is the expected behavior of Postgrest when there are no rows to update, so closing this PR as it's resolved!

@JasonChiu-dev
Copy link

It is so strange to throws 404 error with message of not found!!
On SQL command test, if the data is not found when doing "update" action, the SQL response "Success. No rows returned". It should not throws 404 error with message of not found.

@JasonChiu-dev
Copy link

JasonChiu-dev commented Dec 23, 2022

The library now throws 404 error with message of not found now, which is the expected behavior of Postgrest when there are no rows to update, so closing this PR as it's resolved!

It is so strange to throws 404 error with message of not found!!
On SQL command test, if the data is not found when doing "update" action, the SQL response "Success. No rows returned". It should not throws 404 error with message of not found.

For example, when I have the major table for the basic data (e.g. customers.customerId and customers.name) and then I have the relative table (orders) for the detail data (e.g. orders.numer, orders.customerId (foreign key relate to customer.customerId) ...) ...etc.

It is not necessary that I have to check table (orders) every time when I found I mis-typed the customers.customerId data and try to update customers table and orders table (maybe there were many records in orders table with the mis-typed the customers.customerId, or there is none in orders table using the wrong customers.customerId. I just want to update the customer table with the correct customers.customerId and update the orders table at the same time, even if the wrong customers.customerId data has not been created in the orders table. )

Because you don’t know if the order table has Relevant data, using a relational database, you must update the associated tables and data.

It is not necessary to use the query command to check whether the data has been saved before modifying the data every time. This should be judged and processed by the SQL Update command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working postgrest This issue or pull request is related to postgrest
Projects
None yet
Development

No branches or pull requests

4 participants