Skip to content
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

Type error: referencing missing column count #447

Closed
2 tasks done
davidchalifoux opened this issue Jul 20, 2023 · 7 comments · Fixed by #498
Closed
2 tasks done

Type error: referencing missing column count #447

davidchalifoux opened this issue Jul 20, 2023 · 7 comments · Fixed by #498
Labels
bug Something isn't working released

Comments

@davidchalifoux
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

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

  • Query the count of a nested relationship.
  • Try to reference said value

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

  • OS: macOS 13.5
  • Version of supabase-js: v2.26.0
  • Version of Node.js: v18.17.0
@davidchalifoux davidchalifoux added the bug Something isn't working label Jul 20, 2023
@steve-chavez steve-chavez transferred this issue from supabase/supabase-js Jul 20, 2023
@soedirgo
Copy link
Member

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

@davidchalifoux
Copy link
Author

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

@davidchalifoux
Copy link
Author

davidchalifoux commented Jul 21, 2023

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 column count">.
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
Copy link

jasonpanosso commented Jul 21, 2023

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
Copy link

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

@samuba
Copy link

samuba commented Aug 1, 2023

I have the same problem after upgrading. Also this seems to be a duplicate: #449

bnjmnt4n added a commit to bnjmnt4n/postgrest-js that referenced this issue Nov 5, 2023
bnjmnt4n added a commit to bnjmnt4n/postgrest-js that referenced this issue Feb 8, 2024
bnjmnt4n added a commit to bnjmnt4n/postgrest-js that referenced this issue Feb 23, 2024
bnjmnt4n added a commit to bnjmnt4n/postgrest-js that referenced this issue Mar 3, 2024
steve-chavez pushed a commit that referenced this issue Mar 3, 2024
Copy link

github-actions bot commented Mar 3, 2024

🎉 This issue has been resolved in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants