supabase/supabase-dart

Null check operator used on a null value

carlomigueldy opened this issue · 5 comments

Bug report

Describe the bug

When I query from a table "servers", it returns 500. I think this is coming from the SupabaseClient

{data: null, status: 500, error: {message: Null check operator used on a null value, details: null, hint: null, code: _CastError}, count: null}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a Flutter project and a Supabase project
  2. Configure the Flutter project that will interact with the Supabase project (Setup SUPBASE_URL and SUPABASE_SECRET)
  3. Read records from any table of your Supabase project
  4. {data: null, status: 500, error: {message: Null check operator used on a null value, details: null, hint: null, code: _CastError}, count: null}

Expected behavior

It should return me an array of JSON objects. And status code of 200 and not 500.

Screenshots

This is my supabase client setup

image

This is my query from an abstract class, then my ServerService class extends from it.

image

Then here is where I trigger the call to Supabase API

image

Tap and call method

image

System information

  • OS: Windows
  • Version of supabase-dart: 0.0.1-dev.11
  • Version of Node.js: [e.g. 10.10.0]

Flutter doctor

image

Additional context

In case you might need to see it for yourself, here is my repository link. https://github.com/carlomigueldy/flutter-web-discord-clone

I love supabase since it is a serverless and uses Postgres, I love relational databases :) So thanks for creating that decision instead of going NoSQL.

I cloned your project and I'm getting the same error message. It looks like an exception is thrown in the postgrest package on this line.

And indeed, method on this line is a String? that is never initialised, which throws when calling method!. This could be solved by marking method as required in PostgrestBuilder's constructor or by putting a default value (like "get" for example), not sure what's best.

Actually the issue is that you called .execute() directly on from("servers"). There is no query to execute. Try replacing

final response = await Supabase.client.from("public").execute();

with

final response = await Supabase.client.from("public").select().execute();

Still this is a bit confusing. It should either not be possible to call execute() directly, or it should return a more explicit error.

I implemented a fix here

Thank you @thalkz @phamhieu! Will take a look now.

Will close the issue now.

If this supabase/postgrest-dart@5f6e140 gets merged then would also be great