Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 88388b7

Browse files
committed
fix: stop schema method persisting across all queries
1 parent 0045440 commit 88388b7

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

postgrest/_async/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ def create_session(
6060
http2=True,
6161
)
6262

63+
def schema(self, schema: str):
64+
"""Switch to another schema."""
65+
return AsyncPostgrestClient(
66+
base_url=self.base_url,
67+
schema=schema,
68+
headers=self.headers,
69+
timeout=self.timeout,
70+
verify=self.verify,
71+
proxy=self.proxy,
72+
)
73+
6374
async def __aenter__(self) -> AsyncPostgrestClient:
6475
return self
6576

postgrest/_sync/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ def create_session(
6060
http2=True,
6161
)
6262

63+
def schema(self, schema: str):
64+
"""Switch to another schema."""
65+
return SyncPostgrestClient(
66+
base_url=self.base_url,
67+
schema=schema,
68+
headers=self.headers,
69+
timeout=self.timeout,
70+
verify=self.verify,
71+
proxy=self.proxy,
72+
)
73+
6374
def __enter__(self) -> SyncPostgrestClient:
6475
return self
6576

postgrest/_sync/request_builder.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434
http_method: str,
3535
headers: Headers,
3636
params: QueryParams,
37-
json: Union[dict, list],
37+
json: dict,
3838
) -> None:
3939
self.session = session
4040
self.path = path
@@ -290,7 +290,7 @@ def select(
290290
*columns: The names of the columns to fetch.
291291
count: The method to use to get the count of rows returned.
292292
Returns:
293-
:class:`SyncSelectRequestBuilder`
293+
:class:`AsyncSelectRequestBuilder`
294294
"""
295295
method, params, headers, json = pre_select(*columns, count=count, head=head)
296296
return SyncSelectRequestBuilder[_ReturnT](
@@ -317,7 +317,7 @@ def insert(
317317
Otherwise, use the default value for the column.
318318
Only applies for bulk inserts.
319319
Returns:
320-
:class:`SyncQueryRequestBuilder`
320+
:class:`AsyncQueryRequestBuilder`
321321
"""
322322
method, params, headers, json = pre_insert(
323323
json,
@@ -353,7 +353,7 @@ def upsert(
353353
not when merging with existing rows under `ignoreDuplicates: false`.
354354
This also only applies when doing bulk upserts.
355355
Returns:
356-
:class:`SyncQueryRequestBuilder`
356+
:class:`AsyncQueryRequestBuilder`
357357
"""
358358
method, params, headers, json = pre_upsert(
359359
json,
@@ -381,7 +381,7 @@ def update(
381381
count: The method to use to get the count of rows returned.
382382
returning: Either 'minimal' or 'representation'
383383
Returns:
384-
:class:`SyncFilterRequestBuilder`
384+
:class:`AsyncFilterRequestBuilder`
385385
"""
386386
method, params, headers, json = pre_update(
387387
json,
@@ -404,7 +404,7 @@ def delete(
404404
count: The method to use to get the count of rows returned.
405405
returning: Either 'minimal' or 'representation'
406406
Returns:
407-
:class:`SyncFilterRequestBuilder`
407+
:class:`AsyncFilterRequestBuilder`
408408
"""
409409
method, params, headers, json = pre_delete(
410410
count=count,

postgrest/base_client.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ def __init__(
2323
) -> None:
2424
if not is_http_url(base_url):
2525
ValueError("base_url must be a valid HTTP URL string")
26-
headers = {
26+
27+
self.base_url = base_url
28+
self.headers = {
2729
**headers,
2830
"Accept-Profile": schema,
2931
"Content-Profile": schema,
3032
}
31-
self.session = self.create_session(base_url, headers, timeout, verify, proxy)
33+
self.timeout = timeout
34+
self.verify = verify
35+
self.proxy = proxy
36+
self.session = self.create_session(
37+
self.base_url, self.headers, self.timeout, self.verify, self.proxy
38+
)
3239

3340
@abstractmethod
3441
def create_session(
@@ -68,13 +75,3 @@ def auth(
6875
"Neither bearer token or basic authentication scheme is provided"
6976
)
7077
return self
71-
72-
def schema(self, schema: str):
73-
"""Switch to another schema."""
74-
self.session.headers.update(
75-
{
76-
"Accept-Profile": schema,
77-
"Content-Profile": schema,
78-
}
79-
)
80-
return self

tests/_async/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def test_auth_basic(self, postgrest_client: AsyncPostgrestClient):
6262

6363

6464
def test_schema(postgrest_client: AsyncPostgrestClient):
65-
postgrest_client.schema("private")
66-
session = postgrest_client.session
65+
client = postgrest_client.schema("private")
66+
session = client.session
6767
subheaders = {
6868
"accept-profile": "private",
6969
"content-profile": "private",

tests/_sync/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def test_auth_basic(self, postgrest_client: SyncPostgrestClient):
6161

6262

6363
def test_schema(postgrest_client: SyncPostgrestClient):
64-
postgrest_client.schema("private")
65-
session = postgrest_client.session
64+
client = postgrest_client.schema("private")
65+
session = client.session
6666
subheaders = {
6767
"accept-profile": "private",
6868
"content-profile": "private",

0 commit comments

Comments
 (0)