supabase-py: rpc() - value is not a valid list
Describe the bug
rpc() crashes (calling a db function) with following error:
./tests/test_claims.py::test_get_claims Failed: [undefined]postgrest.exceptions.APIError: {‘provider’: ‘email’, ‘providers’: [‘email’], ‘claims_admin’: True} self = <postgrest._sync.request_builder.SyncFilterRequestBuilder object at 0x103d5a680>
def execute(self) -> APIResponse: """Execute the query. .. tip:: This is the last method called, after the query is built. Returns: :class:`APIResponse` Raises: :class:`APIError` If the API raised an error. """ r = self.session.request( self.http_method, self.path, json=self.json, params=self.params, headers=self.headers, ) try: if ( 200 <= r.status_code <= 299 ): # Response.ok from JS (https://developer.mozilla.org/en-US/docs/Web/API/Response/ok)return APIResponse.from_http_request_response(r)env/lib/python3.10/site-packages/postgrest/_sync/request_builder.py:66:
cls = <class ‘postgrest.base_request_builder.APIResponse’> request_response = <Response [200 OK]>
@classmethod def from_http_request_response( cls: Type[APIResponse], request_response: RequestResponse ) -> APIResponse: try: data = request_response.json() except JSONDecodeError as e: return cls(data=[], count=0) count = cls._get_count_from_http_request_response(request_response)return cls(data=data, count=count)env/lib/python3.10/site-packages/postgrest/base_request_builder.py:162:
??? E pydantic.error_wrappers.ValidationError: 1 validation error for APIResponse E data E value is not a valid list (type=type_error.list)
pydantic/main.py:342: ValidationError
The above exception was the direct cause of the following exception:
def test_get_claims(): client = get_client()claims = get_claims(client, USER_ID)tests/test_claims.py:11:
middlewares/claims.py:27: in get_claims res = client.rpc(“get_claims”, {“uid”: uid}).execute()
Using get_claims function from:
https://github.com/wantpinow/supabase-custom-claims/blob/patch-1/install.sql
Is it because the function returns a jsonb ?
To Reproduce
Steps to reproduce the behavior:
- Install the function
get_claimsfrom this PR https://github.com/wantpinow/supabase-custom-claims/blob/patch-1/install.sql - Call it from latest version of supabase-py
Expected behavior
Returns the function output
Desktop (please complete the following information):
- OS: MacOS 13.3
- Version
supabase==1.0.2
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 3
- Comments: 16 (7 by maintainers)
change
result = supabase.rpc("get_headphones_products", {})TOresult = await supabase.rpc("get_headphones_products", {}).execute()Hey,
Wanted to echo the sentiment above ^ we’ll push out a fix shortly
A PR has been opened to fix this issue and we will get it merged in soon https://github.com/supabase-community/postgrest-py/pull/309
This should now be available in the latest v1.1.0 of the
supabase-pylibrary.@ShantanuNair we have seen this issue and are currently looking into it.
I still have the issue, when trying this ans=supabase_client.rpc(“count_duplicate_emails”,{}) I get <postgrest._sync.request_builder.SyncFilterRequestBuilder object at 0x10fe32ee0> and when trying ans=await supabase_client.rpc(“count_duplicate_emails”, {}).execute() it returns AttributeError: ‘int’ object has no attribute ‘get’, it works when calling with a Post request, but not with the Supabase python library
I have the same issue when calling a function. the same code worked well in javascript
the response is: <postgrest._sync.request_builder.SyncFilterRequestBuilder object at 0x10fe32ee0>
@louis030195 @modyabhi @e-gons I had the same issue. Was able to make it work with the Table return type in the function. For example following function is working:
CREATE OR REPLACE FUNCTION get_ids(id text) RETURNS TABLE (id text[]) AS $$ BEGIN RETURN QUERY ( SELECT array_agg(id::text) FROM ( SELECT id FROM table1 LIMIT 20 ) subquery ); END; $$ LANGUAGE plpgsql;And I get the same error if I get any other return type i.e. json, text , array etc.
Bumping this, same issue here when the function returns a value on version 1.0.3.
FUNCTION CODE:
PYTHON MODULE:
ERROR:
Similar issue here where a stored function returns a
NUMERIC