From cbb4ccfcd45d317d94fd07c6e4459d4e43cf0c68 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Sat, 24 Feb 2024 00:52:45 +0000 Subject: [PATCH 1/2] Update rpc return type --- supabase/_async/client.py | 4 ++-- supabase/_sync/client.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/supabase/_async/client.py b/supabase/_async/client.py index 266a7c63..eae9292d 100644 --- a/supabase/_async/client.py +++ b/supabase/_async/client.py @@ -5,9 +5,9 @@ from gotrue.types import AuthChangeEvent, Session from httpx import Timeout from postgrest import ( - AsyncFilterRequestBuilder, AsyncPostgrestClient, AsyncRequestBuilder, + AsyncRPCFilterRequestBuilder, ) from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT from storage3 import AsyncStorageClient @@ -119,7 +119,7 @@ def from_(self, table_name: str) -> AsyncRequestBuilder: """ return self.postgrest.from_(table_name) - def rpc(self, fn: str, params: Dict[Any, Any]) -> AsyncFilterRequestBuilder: + def rpc(self, fn: str, params: Dict[Any, Any] = {}) -> AsyncRPCFilterRequestBuilder: """Performs a stored procedure call. Parameters diff --git a/supabase/_sync/client.py b/supabase/_sync/client.py index e761f819..29776e31 100644 --- a/supabase/_sync/client.py +++ b/supabase/_sync/client.py @@ -4,7 +4,11 @@ from gotrue import SyncMemoryStorage from gotrue.types import AuthChangeEvent, Session from httpx import Timeout -from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder +from postgrest import ( + SyncPostgrestClient, + SyncRequestBuilder, + SyncRPCFilterRequestBuilder, +) from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT from storage3 import SyncStorageClient from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT @@ -115,7 +119,7 @@ def from_(self, table_name: str) -> SyncRequestBuilder: """ return self.postgrest.from_(table_name) - def rpc(self, fn: str, params: Dict[Any, Any]) -> SyncFilterRequestBuilder: + def rpc(self, fn: str, params: Dict[Any, Any] = {}) -> SyncRPCFilterRequestBuilder: """Performs a stored procedure call. Parameters From 2f97e6bfb8449260af517eb4f41fa0abac988d93 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Sat, 24 Feb 2024 01:00:56 +0000 Subject: [PATCH 2/2] Add check to see if default params is none --- supabase/_async/client.py | 8 ++++++-- supabase/_sync/client.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/supabase/_async/client.py b/supabase/_async/client.py index eae9292d..94df4259 100644 --- a/supabase/_async/client.py +++ b/supabase/_async/client.py @@ -1,5 +1,5 @@ import re -from typing import Any, Dict, Union +from typing import Any, Dict, Optional, Union from gotrue import AsyncMemoryStorage from gotrue.types import AuthChangeEvent, Session @@ -119,7 +119,9 @@ def from_(self, table_name: str) -> AsyncRequestBuilder: """ return self.postgrest.from_(table_name) - def rpc(self, fn: str, params: Dict[Any, Any] = {}) -> AsyncRPCFilterRequestBuilder: + def rpc( + self, fn: str, params: Optional[Dict[Any, Any]] = None + ) -> AsyncRPCFilterRequestBuilder: """Performs a stored procedure call. Parameters @@ -135,6 +137,8 @@ def rpc(self, fn: str, params: Dict[Any, Any] = {}) -> AsyncRPCFilterRequestBuil Returns a filter builder. This lets you apply filters on the response of an RPC. """ + if params is None: + params = {} return self.postgrest.rpc(fn, params) @property diff --git a/supabase/_sync/client.py b/supabase/_sync/client.py index 29776e31..faefc6c0 100644 --- a/supabase/_sync/client.py +++ b/supabase/_sync/client.py @@ -1,5 +1,5 @@ import re -from typing import Any, Dict, Union +from typing import Any, Dict, Optional, Union from gotrue import SyncMemoryStorage from gotrue.types import AuthChangeEvent, Session @@ -119,7 +119,9 @@ def from_(self, table_name: str) -> SyncRequestBuilder: """ return self.postgrest.from_(table_name) - def rpc(self, fn: str, params: Dict[Any, Any] = {}) -> SyncRPCFilterRequestBuilder: + def rpc( + self, fn: str, params: Optional[Dict[Any, Any]] = None + ) -> SyncRPCFilterRequestBuilder: """Performs a stored procedure call. Parameters @@ -135,6 +137,8 @@ def rpc(self, fn: str, params: Dict[Any, Any] = {}) -> SyncRPCFilterRequestBuild Returns a filter builder. This lets you apply filters on the response of an RPC. """ + if params is None: + params = {} return self.postgrest.rpc(fn, params) @property