fix: mutable reference headers #1095#1096
Conversation
|
@olirice Sorry, I can not set reviewer. That's why , I request a review here. |
Pull Request Test Coverage Report for Build 15212706024Details
💛 - Coveralls |
grdsdev
left a comment
There was a problem hiding this comment.
Thanks for the fix @AsahiSoftWareEngineer just some clarifications before merging.
supabase/_sync/client.py
Outdated
| 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.
not sure the issue this is solving, could you elaborate?
There was a problem hiding this comment.
Sorry, Below source code is not necessary.
self.postgrest.session.headers["Authorization"] = header
self.storage.session.headers["Authorization"] = headerCaused by using deep-copy, before source code was not working. (auth._headers is not refreshed).
That's why, I changed to reassign deep-copied self._create_auth_header(access_token)methods
|
@grdsdev Sorry, I fixed it. Please re-review pull request. |
|
I think this would be better addressed by using the I wrote your test below using the def test_mutable_headers_issue():
url = os.environ.get("SUPABASE_TEST_URL")
key = os.environ.get("SUPABASE_TEST_KEY")
shared_options = ClientOptions(
headers={"Authorization": "Bearer initial-token", "x-site": "supanew.site"}
)
client1 = create_client(url, key, shared_options)
client2 = create_client(url, key, shared_options)
client1.options.replace({"headers": {"Authorization": "Bearer modified-token"}})
assert client2.options.headers["Authorization"] == "Bearer initial-token"
assert client2.options.headers["x-site"] == "supanew.site"
assert client1.options.headers["x-site"] == "supanew.site" |
|
@silentworks Sure. I think of trying, but I do not know Can I rewrite docs.(Have I permissions??) |
|
All test passed |
|
@grdsdev Hi, Can you re-review pull request. |
@silentworks I just think I prefer to internally deep copy the client options object, I think that just makes more sense then having to use a separate |
|
@grdsdev this is fine. I do however think we are trying to fix a language (python being dynamic by design) issue here but I am OK with this PR being merged in. |
that makes sense, let's not fight the language. |
|
@AsahiSoftWareEngineer thank you for this contributions, but as said by @silentworks there're other ways of achieving this by using the |
|
We're re-opening this PR as I've realised in my tests I didn't test it fully. def test_mutable_headers_issue():
url = os.environ.get("SUPABASE_TEST_URL")
key = os.environ.get("SUPABASE_TEST_KEY")
shared_options = ClientOptions(
headers={"Authorization": "Bearer initial-token", "x-site": "supanew.site"}
)
client1 = create_client(url, key, shared_options)
client2 = create_client(url, key, shared_options)
client1.options = client1.options.replace(headers={**client1.options.headers, "Authorization": "Bearer modified-token"})
assert client1.options.headers["Authorization"] == "Bearer modified-token"
assert client2.options.headers["Authorization"] == "Bearer initial-token"
assert client2.options.headers["x-site"] == "supanew.site"
assert client1.options.headers["x-site"] == "supanew.site" |
What kind of change does this PR introduce?
Bug fix Isses #1095
What is the current behavior?
Isses No. #1095
What is the new behavior?
Prevent unintended header changes when sharing the same
ClientOptions.