supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
964 stars 128 forks source link

Type error: referencing missing column `count` #447

Closed davidchalifoux closed 3 months ago

davidchalifoux commented 11 months ago

Bug report

Describe the bug

After upgrading @supabase/supabase-js to 2.26.0, I'm now getting a type error when querying count for a nested relationship. The API is returning the count exactly as before, so it's only a type issue.

To Reproduce

Example query:

const response = await supabase
    .from("brands")
    .select(
      "*, brand_categories!brands_category_id_fkey(*), brand_subcategories(*, brand_categories(*)), brand_statuses(*), brand_locations(count)",
      { count: "estimated", head: false }
    );

In this example, brand_locations(count) is what's causing the error. The returned type for that field is SelectQueryError even though no error is thrown from the API.

Expected behavior

The returned type of a count should not be SelectQueryError.

Screenshots

Screenshot 2023-07-20 at 10 23 40 AM

System information

soedirgo commented 11 months ago

Thanks David, I'll try to reproduce this. Is count a normal column of brand_locations? Or a computed column etc.?

davidchalifoux commented 11 months ago

@soedirgo Thank you! No, it is not a normal or computed column.

davidchalifoux commented 11 months ago

It's actually happening to me with a much simpler query:

const res = await supabase
      .from("brand_locations")
      .select("count", { count: "estimated", head: true })
      .eq("brand_id", brandId);

Again, it's returning SelectQueryError<"Referencing missing columncount">. I also tested it on other tables in my database, and it's happening with every one of them. Could it be an issue with supabase gen types?

EDIT: Nevermind, I forgot you don't need to select count if it's not a foreign table.

jasonpanosso commented 11 months ago

This is happening to me with this query:

  const someQuery = await supabase
    .from('someTable')
    .select(
      `id,
       fk:foreign_key_id(id, name)
      `
    )

I believe it has to do with this pr

I've verified that my types file is correct, the column name exists on the foreign table, and foreign_key_id is configured as a foreign key to the table I expect it to be referencing(confirmed in types file). Also, at runtime, this works completely as expected with no issues.

I believe the expected behaviour is that fk should be unknown, or {}[]? This works fine if I put * instead of specifying columns. Not 100% sure on what the intended behavior is, or if my issue is directly related to this one. I'm just getting the same error, and they seem very similar

jasonpanosso commented 11 months ago

@soedirgo did you ever get a chance to test? Curious if this is intended behavior, or a bug

samuba commented 11 months ago

I have the same problem after upgrading. Also this seems to be a duplicate: https://github.com/supabase/postgrest-js/issues/449

github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 1.13.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: