Skip to content

Commit b0dd496

Browse files
authored
fix!: schema method persisting only on current query (#575)
1 parent 0045440 commit b0dd496

File tree

6 files changed

+36
-17
lines changed

6 files changed

+36
-17
lines changed

postgrest/_async/client.py

+11
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

+11
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

+1-1
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

postgrest/base_client.py

+9-12
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

+2-2
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

+2-2
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)