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

single() returns Invalid media type: expected no more input. #921

Open
Mykyta-Chernenko opened this issue May 8, 2024 · 19 comments · May be fixed by #946
Open

single() returns Invalid media type: expected no more input. #921

Mykyta-Chernenko opened this issue May 8, 2024 · 19 comments · May be fixed by #946
Labels
bug Something isn't working postgrest This issue or pull request is related to postgrest

Comments

@Mykyta-Chernenko
Copy link

Describe the bug
When single() doesn't find anything, I get "Invalid media type: expected no more input."

full error
flutter: Event: MatchError, Properties: {error: Error on line 1, column 32: Invalid media type: expected no more input.

1 │ application/json; charset=utf-8,application/vnd.pgrst.object+json; charset=utf-8
│ ^
╵}
flutter: Error fetching match: Error on line 1, column 32: Invalid media type: expected no more input.

1 │ application/json; charset=utf-8,application/vnd.pgrst.object+json; charset=utf-8
│ ^

To Reproduce
Steps to reproduce the behavior:

  1. install supabase_flutter: ^2.5.1
  2. try to call do something as
    await supabase
    .from('profile')
    .select()
    .eq('id', 'gibberish')
    .single();
  3. See error

Expected behavior
Some ordinary exception as "not found"

Version (please complete the following information):
├── supabase_flutter 2.5.1
│ ├── supabase 2.1.1
│ │ ├── functions_client 2.0.0
│ │ ├── gotrue 2.6.0
│ │ ├── postgrest 2.1.1
│ │ ├── realtime_client 2.0.4
│ │ ├── storage_client 2.0.1

@Mykyta-Chernenko Mykyta-Chernenko added the bug Something isn't working label May 8, 2024
@dshukertjr dshukertjr added the postgrest This issue or pull request is related to postgrest label May 9, 2024
@allipiopereira
Copy link

I'm also having the same error.

supabase: 1.11.11
supabase_flutter: 1.10.24

@Vinzent03
Copy link
Collaborator

Is that all stacktrace you get? Shouldn't there be some info about in which file and line it occurs?

@Mykyta-Chernenko
Copy link
Author

Mykyta-Chernenko commented May 10, 2024

unfortunately and surprisingly, this is the whole stack, I don't get anything else.
UPD

sorry, my bad, forgot to rethrow, here is the whole stack.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Error on line 1, column 32: Invalid media type: expected no more input.

1 │ application/json; charset=utf-8,application/vnd.pgrst.object+json; charset=utf-8
│ ^

#0 wrapFormatException (package:http_parser/src/utils.dart:15:5)
#1 new MediaType.parse (package:http_parser/src/media_type.dart:46:7)
#2 _contentTypeForHeaders (package:http/src/response.dart:79:45)
#3 _encodingForHeaders (package:http/src/response.dart:72:24)
#4 Response.body (package:http/src/response.dart:28:22)
#5 PostgrestBuilder._parseResponse (package:postgrest/src/postgrest_builder.dart:269:31)
#6 PostgrestBuilder._execute (package:postgrest/src/postgrest_builder.dart:164:14)

#7 PostgrestBuilder.then (package:postgrest/src/postgrest_builder.dart:372:24)

Is that all stacktrace you get? Shouldn't there be some info about in which file and line it occurs?

@Smartiiez
Copy link

Smartiiez commented May 13, 2024

I think you have to use :
await supabase.from('profile').select().eq('id', 'gibberish').maybeSingle();

@Mykyta-Chernenko
Copy link
Author

I think you have to use : await supabase.from('profile').select().eq('id', 'gibberish').maybeSingle();

It's possible temporary solution

but with 30 .single() queries in prod, it was almost impossible to debug the first time where the issue happened at/neither to catch it

@dshukertjr
Copy link
Member

@Mykyta-Chernenko @allipiopereira
Hmm, I am unable to reproduce this issue. When I use .single() and query in a way that it returns 0 rows, I get the following error.

PostgrestException(message: JSON object requested, multiple (or no) rows returned, code: PGRST116, details: The result contains 0 rows, hint: null).

Are you using the hosted version of Supabase? Does the same issue happen on a fresh Supabase instance?

@Mykyta-Chernenko
Copy link
Author

@Mykyta-Chernenko @allipiopereira Hmm, I am unable to reproduce this issue. When I use .single() and query in a way that it returns 0 rows, I get the following error.

PostgrestException(message: JSON object requested, multiple (or no) rows returned, code: PGRST116, details: The result contains 0 rows, hint: null).

Are you using the hosted version of Supabase? Does the same issue happen on a fresh Supabase instance?

I get the error like this.

   final response = await supabase
        .from('app_settings')
        .select('review_version_ios, review_version_android')
        .single();
    
    id is non-existent
    
    I get 
    
    [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Error on line 1, column 32: Invalid media type: expected no more input.
  ╷
1 │ application/json; charset=utf-8,application/vnd.pgrst.object+json; charset=utf-8
  │                                ^
  ╵
#0      wrapFormatException (package:http_parser/src/utils.dart:15:5)
#1      new MediaType.parse (package:http_parser/src/media_type.dart:46:7)
#2      _contentTypeForHeaders (package:http/src/response.dart:79:45)
#3      _encodingForHeaders (package:http/src/response.dart:72:24)
#4      Response.body (package:http/src/response.dart:28:22)
#5      PostgrestBuilder._parseResponse (package:postgrest/src/postgrest_builder.dart:269:31)
#6      PostgrestBuilder._execute (package:postgrest/src/postgrest_builder.dart:164:14)
<asynchronous suspension>
#7      PostgrestBuilder.then (package:postgrest/src/postgrest_builder.dart:372:24)
<asynchronous suspension>

I use supabase hosted version.

I tried to restart the db, the issue is still there

I created a new db with the minimum migration, the issue is still there

here is the migration I applied to the fresh db

-- Migration for the app_settings table
create table if not exists app_settings
(
    id                     serial primary key,
    review_version         text not null,
    review_version_android text not null,
    review_version_ios     text not null,
    version                text not null
);

I use Frankfurt region.

Thanks for you help!

@Dosenbiiir
Copy link

I get the same error message, so I can confirm that. Also I get the same message if .single() is used and multiple results are returned. I tested supabase_flutter: ^2.3.4 and ^2.5.3.

@blank124
Copy link

blank124 commented Jun 8, 2024

Having same issue

@dshukertjr
Copy link
Member

Anyone facing this issue, would you be able to let me know what version of PostgREST you are running on the Supabase instance?

@Mykyta-Chernenko
Copy link
Author

Anyone facing this issue, would you be able to let me know what version of PostgREST you are running on the Supabase instance?

Auth version
2.152.1
PostgREST version
12.0.2
Postgres version
15.1.1.44

@dshukertjr
Copy link
Member

Hmm, I aligned the PostgREST version, but am still unable to reproduce the issue.

Is anyone willing to share their Supabase URL and Anon key so that I can make the query on my end to dig into this issue? Feel free to DM me on Twitter if you are not comfortable sharing them here.
https://x.com/dshukertjr

@Mykyta-Chernenko
Copy link
Author

Hmm, I aligned the PostgREST version, but am still unable to reproduce the issue.

Is anyone willing to share their Supabase URL and Anon key so that I can make the query on my end to dig into this issue? Feel free to DM me on Twitter if you are not comfortable sharing them here. https://x.com/dshukertjr

sent over twitter

@dshukertjr
Copy link
Member

dshukertjr commented Jun 10, 2024

@Mykyta-Chernenko
Still unable to reproduce this issue. I am getting the following response performing the following sample query that you have shared on an iOS simulator.

PostgrestException(message: JSON object requested, multiple (or no) rows returned, code: PGRST116, details: The result contains 0 rows, hint: null)
final response = await supabase
        .from('app_settings')
        .select('review_version_ios, review_version_android')
        .single();

I wonder what the difference between your environment and my environment could be. What platform have you tried? I have tried iOS and web, and didn't get the error that you are facing on either one of them.

@sunsreng
Copy link

sunsreng commented Jul 4, 2024

i have the same issue, here is my play around

      final response = await client.from('users').select().eq('id', userId);
      if (response.isEmpty) return null;

      return UserModel.fromJson(response.first);

@Dosenbiiir
Copy link

I upgraded the PostgREST version from 12.0.2 to 12.2.1 and Postgres version from 15.1.1.33 to 15.1.1.73. The weird error message is fixed now.

@wind-flow
Copy link

wind-flow commented Jul 7, 2024

I have same issue when I use rpc.

final result = await supabase
.rpc(SupabaseRPCName.fetchMonthlyPostingHistory, params: {
'user_id': userId,
'target_year': targetYear,
'target_month': targetMonth,
'pet_id': petId,
}).single();

@BohdanSamusko
Copy link

I had the same issue and upgrading to the latest version fixed the error 🚀

Auth version
2.158.1
PostgREST version
12.2.3
Postgres version
15.6.1.115

@Vinzent03
Copy link
Collaborator

I would close this issue as it seems that upgrading the postgrest version seems to solve the issue. Anyone here still having the issue after upgrading?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working postgrest This issue or pull request is related to postgrest
Projects
None yet
10 participants