Skip to content

Commit

Permalink
Merge pull request #579 from supabase-community/j0/convert_functions_…
Browse files Browse the repository at this point in the history
…into_property

feat: add functions property
  • Loading branch information
J0 authored Oct 4, 2023
2 parents 11b014d + c283c8c commit 7cf9f84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 12 additions & 0 deletions supabase/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion tests/test_function_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7cf9f84

Please sign in to comment.