-
-
Notifications
You must be signed in to change notification settings - Fork 269
Fix mutable reference headers #1095 #1096
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
f3529a8
d5302d5
02eca96
505bf6d
a4291bc
34ed12c
b804c29
c6d4cdf
d1495bc
7ac3df2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import copy | ||
import re | ||
from typing import Any, Dict, List, Optional, Union | ||
|
||
|
@@ -62,13 +63,11 @@ def __init__( | |
r"^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$", supabase_key | ||
): | ||
raise SupabaseException("Invalid API key") | ||
|
||
if options is None: | ||
options = ClientOptions(storage=SyncMemoryStorage()) | ||
|
||
self.supabase_url = supabase_url | ||
self.supabase_key = supabase_key | ||
self.options = options | ||
self.options = copy.deepcopy(options) | ||
options.headers.update(self._get_auth_headers()) | ||
self.rest_url = f"{supabase_url}/rest/v1" | ||
self.realtime_url = f"{supabase_url}/realtime/v1".replace("http", "ws") | ||
|
@@ -100,17 +99,15 @@ def create( | |
): | ||
auth_header = options.headers.get("Authorization") if options else None | ||
client = cls(supabase_url, supabase_key, options) | ||
|
||
session_access_token = None | ||
if auth_header is None: | ||
try: | ||
session = client.auth.get_session() | ||
session_access_token = client._create_auth_header(session.access_token) | ||
except Exception as err: | ||
session_access_token = None | ||
|
||
client.options.headers.update( | ||
client._get_auth_headers(session_access_token) | ||
) | ||
client.options.headers.update(client._get_auth_headers(session_access_token)) | ||
|
||
return client | ||
|
||
|
@@ -293,8 +290,11 @@ def _listen_to_auth_events( | |
self._storage = None | ||
self._functions = None | ||
access_token = session.access_token if session else self.supabase_key | ||
|
||
self.options.headers["Authorization"] = self._create_auth_header(access_token) | ||
header = copy.deepcopy(self._create_auth_header(access_token)) | ||
self.options.headers["Authorization"] = header | ||
self.auth._headers["Authorization"] = header | ||
self.postgrest.session.headers["Authorization"] = header | ||
self.storage.session.headers["Authorization"] = header | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure the issue this is solving, could you elaborate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, Below source code is not necessary. self.postgrest.session.headers["Authorization"] = header
self.storage.session.headers["Authorization"] = header Caused by using deep-copy, before source code was not working. (auth._headers is not refreshed). |
||
|
||
def create_client( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just noticed this line updates the passed param, not the instance options variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite
options.headers.update(self._get_auth_headers())
toself.options.headers.update(self._get_auth_headers())
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like this change was made. Also note you only need to make changes in the
_async/client
and then runmake build_sync
andmake tests_pre_commit
in the terminal after.