GetDutchie / brick

An intuitive way to work with persistent data in Dart
https://getdutchie.github.io/brick/#/
364 stars 28 forks source link

[Supabase integration]: Null check exception thrown in PostgrestBuilder when upserting while being offline #439

Closed devj3ns closed 1 month ago

devj3ns commented 1 month ago

This morning, I tested if the app I am migrating to the new Supabase integration still works offline. Unfortunately, when I upsert a model while being offline, the following exception is thrown:

Null check operator used on a null value
#0      PostgrestBuilder._parseResponse (package:postgrest/src/postgrest_builder.dart:254:27)
#1      PostgrestBuilder._execute (package:postgrest/src/postgrest_builder.dart:164:14)
<asynchronous suspension>
#2      PostgrestBuilder.then (package:postgrest/src/postgrest_builder.dart:372:24)
<asynchronous suspension>

I checked the debugger, and the exception is thrown in this line inside the _upsertByType function of the SupabaseProvider:

final resp = await builder.select(queryTransformer.selectFields).limit(1).maybeSingle();

I can also reproduce this issue with the example_supbase flutter app. (For that, I added a button which upserts a new customer because currently the example only displays the customers but does not allow adding a new one).

tshedor commented 1 month ago

@devj3ns Good catch; fixed and merged in #436 . I haven't published this.

devj3ns commented 1 month ago

@tshedor, thanks! I'll do some more tests on Monday and report back if there are any other issues or bugs.

devj3ns commented 1 month ago

I just tested it and the exception is gone now. Thanks for the quick fix!