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

Getting 406s in network logs if .maybeSingle() returns no result #361

Closed
probablykasper opened this issue Oct 31, 2022 · 9 comments · Fixed by #486
Closed

Getting 406s in network logs if .maybeSingle() returns no result #361

probablykasper opened this issue Oct 31, 2022 · 9 comments · Fixed by #486
Labels
enhancement New feature or request postgrest-patch-needed Requires a change on PostgREST released

Comments

@probablykasper
Copy link

probablykasper commented Oct 31, 2022

Bug report

Describe the bug

When selecting using .maybeSingle(), I'm getting an error logged to console if there's 0 rows returned. There's no error if I remove .maybeSingle(), and there's no error if a row is returned.

To be clear, the query still returns successfully.

image

The stack trace seems to points to this line (probably a bad source map):

count = parseInt(contentRange[1])

To Reproduce

	const profileResult = await supabaseClient
		.from('profiles')
		.select()
		.eq('id', session.user.id)
		.maybeSingle()

System information

  • OS: macOS
  • Browser: Brave
  • Version of supabase-js: 2.0.4
  • Version of Node.js: 16.15.0
@probablykasper probablykasper added the bug Something isn't working label Oct 31, 2022
@soedirgo
Copy link
Member

soedirgo commented Nov 1, 2022

The stack trace seems to points to this line (probably a bad source map)

Hmm the trace points to PostgrestBuilder.ts:70 which looks right:

let res = _fetch(this.url.toString(), {

So it comes from the fetch invocation. I suspect the browser's native fetch is logging all 4xxs - the way we do maybeSingle() is we do single() but ignore the error, so the 406 comes from PostgREST. Should be harmless, but noisy - I suppose we could instead treat it as a non-single() and just throw if there are >1 rows.

@steve-chavez
Copy link
Member

the way we do maybeSingle() is we do single() but ignore the error, so the 406 comes from PostgREST

Not ideal to ignore the error on the client as the logs would also still contain the 406. I think PostgREST/postgrest#2164 (comment) would be the ideal solution.

(basically a header that defines expected number of returned rows)

@soedirgo
Copy link
Member

soedirgo commented Jan 6, 2023

Gotcha, changing this issue to track refactoring the code to use that feature once it's out 👍

@soedirgo soedirgo changed the title Error logged when using .maybeSingle() returns no result Getting 406s in network logs if .maybeSingle() returns no result Jan 6, 2023
@soedirgo soedirgo added enhancement New feature or request postgrest-patch-needed Requires a change on PostgREST and removed bug Something isn't working labels Jan 6, 2023
@brentrobbins
Copy link

Hi @soedirgo Any update on when this might be addressed?

@soedirgo
Copy link
Member

@brentrobbins can try to npm update @supabase/postgrest-js? This should fix most of the cases, the rest will need some changes on PostgREST proper

@otang
Copy link

otang commented Jul 12, 2023

I am using @supabase/postgrest-js@1.7.2 and I'm still having the issue where the API returns 406 errors when using .maybeSingle().

This seems to be a mistake. I would expect this type of query to return a 200 status with a null result, as opposed to a non-200 status.

@francisace
Copy link

Any update on this? For us the issue appears to be this line: https://github.com/supabase/postgrest-js/blob/v0.37.4/src/lib/types.ts#L151 which contains hard coded Results contain 0 rows, currently the endpoint returns The result contains 0 rows in the details

@steve-chavez
Copy link
Member

On PostgREST 11.2.0, the format of the error got changed on PostgREST/postgrest#2876 to "The result contains 0 rows".

I didn't know postgrest-js was relying on the messages. For now we could change the detection to 0 rows. This should work for previous and newer versions.

@github-actions
Copy link

🎉 This issue has been resolved in version 1.8.5 🎉

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
enhancement New feature or request postgrest-patch-needed Requires a change on PostgREST released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants