diff --git a/supabase/client.py b/supabase/client.py index b69115b7..c27a4e70 100644 --- a/supabase/client.py +++ b/supabase/client.py @@ -1,6 +1,7 @@ import re from typing import Any, Dict, Union +from deprecation import deprecated from gotrue.types import AuthChangeEvent from httpx import Timeout from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder @@ -81,8 +82,10 @@ def __init__( self.realtime = None self._postgrest = None self._storage = None + self._functions = None self.auth.on_auth_state_change(self._listen_to_auth_events) + @deprecated("1.1.1", "1.3.0", details="Use `.functions` instead") def functions(self) -> FunctionsClient: return FunctionsClient(self.functions_url, self._get_auth_headers()) @@ -144,6 +147,14 @@ def storage(self): ) return self._storage + @property + def functions(self): + if self._functions is None: + headers = self._get_auth_headers() + headers.update(self._get_token_header()) + self._functions = FunctionsClient(self.functions_url, headers) + return self._functions + # async def remove_subscription_helper(resolve): # try: # await self._close_subscription(subscription) @@ -236,6 +247,7 @@ def _listen_to_auth_events(self, event: AuthChangeEvent, session): # reset postgrest and storage instance on event change self._postgrest = None self._storage = None + self._functions = None def create_client( diff --git a/tests/test_function_configuration.py b/tests/test_function_configuration.py index 876cb05c..0e451d03 100644 --- a/tests/test_function_configuration.py +++ b/tests/test_function_configuration.py @@ -7,7 +7,6 @@ def test_functions_client_initialization() -> None: # Sample JWT Key key = "xxxxxxxxxxxxxx.xxxxxxxxxxxxxxx.xxxxxxxxxxxxxxx" sp = supabase.Client(url, key) - sp.functions() assert sp.functions_url == f"https://{ref}.supabase.co/functions/v1" url = "https://localhost:54322"