Skip to content

feat: add functions property #579

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

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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