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

Commit 60ff26c

Browse files
authored
Merge branch 'main' into silentworks/httpx-dependency-injection
2 parents 0c50d9a + fa90200 commit 60ff26c

17 files changed

+329
-145
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.0.1"
2+
".": "1.0.2"
33
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## [1.0.2](https://github.com/supabase/postgrest-py/compare/v1.0.1...v1.0.2) (2025-05-21)
4+
5+
6+
### Bug Fixes
7+
8+
* pass params as query params for get/head requests ([#593](https://github.com/supabase/postgrest-py/issues/593)) ([576a5b8](https://github.com/supabase/postgrest-py/commit/576a5b84e19c0a379ef10df24f3325c0519d406e))
9+
* validate JSON input for APIError ([#597](https://github.com/supabase/postgrest-py/issues/597)) ([3c8bdae](https://github.com/supabase/postgrest-py/commit/3c8bdae4135f79dcf903d0bd75f02c097db0b855))
10+
311
## [1.0.1](https://github.com/supabase/postgrest-py/compare/v1.0.0...v1.0.1) (2025-03-24)
412

513

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ remove_pytest_asyncio_from_sync:
3838
sed -i 's/_async/_sync/g' tests/_sync/test_client.py
3939
sed -i 's/Async/Sync/g' tests/_sync/test_client.py
4040
sed -i 's/Async/Sync/g' postgrest/_sync/request_builder.py
41+
sed -i 's/_client\.SyncClient/_client\.Client/g' tests/_sync/test_client.py
4142

4243
sleep:
4344
sleep 2

infra/init.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ as $function$
7777
select * from countries;
7878
$function$;
7979

80+
create or replace function public.search_countries_by_name(search_name text)
81+
returns setof countries
82+
language sql
83+
as $function$
84+
select * from countries where nicename ilike '%' || search_name || '%';
85+
$function$;
8086

8187
create table
8288
orchestral_sections (id int8 primary key, name text);

poetry.lock

Lines changed: 117 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

postgrest/_async/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ def rpc(
166166

167167
headers = Headers({"Prefer": f"count={count}"}) if count else Headers()
168168

169+
if method in ("HEAD", "GET"):
170+
return AsyncRPCFilterRequestBuilder[Any](
171+
self.session,
172+
f"/rpc/{func}",
173+
method,
174+
headers,
175+
QueryParams(params),
176+
json={},
177+
)
169178
# the params here are params to be sent to the RPC and not the queryparams!
170179
return AsyncRPCFilterRequestBuilder[Any](
171180
self.session, f"/rpc/{func}", method, headers, QueryParams(), json=params

postgrest/_async/request_builder.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from json import JSONDecodeError
43
from typing import Any, Generic, Optional, TypeVar, Union
54

65
from httpx import Headers, QueryParams
@@ -19,7 +18,7 @@
1918
pre_update,
2019
pre_upsert,
2120
)
22-
from ..exceptions import APIError, generate_default_error_message
21+
from ..exceptions import APIError, APIErrorFromJSON, generate_default_error_message
2322
from ..types import ReturnMethod
2423
from ..utils import AsyncClient, get_origin_and_cast
2524

@@ -75,10 +74,9 @@ async def execute(self) -> APIResponse[_ReturnT]:
7574
return body
7675
return APIResponse[_ReturnT].from_http_request_response(r)
7776
else:
78-
raise APIError(r.json())
77+
json_obj = APIErrorFromJSON.model_validate_json(r.content)
78+
raise APIError(dict(json_obj))
7979
except ValidationError as e:
80-
raise APIError(r.json()) from e
81-
except JSONDecodeError:
8280
raise APIError(generate_default_error_message(r))
8381

8482

@@ -124,10 +122,9 @@ async def execute(self) -> SingleAPIResponse[_ReturnT]:
124122
): # Response.ok from JS (https://developer.mozilla.org/en-US/docs/Web/API/Response/ok)
125123
return SingleAPIResponse[_ReturnT].from_http_request_response(r)
126124
else:
127-
raise APIError(r.json())
125+
json_obj = APIErrorFromJSON.model_validate_json(r.content)
126+
raise APIError(dict(json_obj))
128127
except ValidationError as e:
129-
raise APIError(r.json()) from e
130-
except JSONDecodeError:
131128
raise APIError(generate_default_error_message(r))
132129

133130

postgrest/_sync/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ def rpc(
166166

167167
headers = Headers({"Prefer": f"count={count}"}) if count else Headers()
168168

169+
if method in ("HEAD", "GET"):
170+
return SyncRPCFilterRequestBuilder[Any](
171+
self.session,
172+
f"/rpc/{func}",
173+
method,
174+
headers,
175+
QueryParams(params),
176+
json={},
177+
)
169178
# the params here are params to be sent to the RPC and not the queryparams!
170179
return SyncRPCFilterRequestBuilder[Any](
171180
self.session, f"/rpc/{func}", method, headers, QueryParams(), json=params

postgrest/_sync/request_builder.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from json import JSONDecodeError
43
from typing import Any, Generic, Optional, TypeVar, Union
54

65
from httpx import Headers, QueryParams
@@ -19,7 +18,7 @@
1918
pre_update,
2019
pre_upsert,
2120
)
22-
from ..exceptions import APIError, generate_default_error_message
21+
from ..exceptions import APIError, APIErrorFromJSON, generate_default_error_message
2322
from ..types import ReturnMethod
2423
from ..utils import SyncClient, get_origin_and_cast
2524

@@ -75,10 +74,9 @@ def execute(self) -> APIResponse[_ReturnT]:
7574
return body
7675
return APIResponse[_ReturnT].from_http_request_response(r)
7776
else:
78-
raise APIError(r.json())
77+
json_obj = APIErrorFromJSON.model_validate_json(r.content)
78+
raise APIError(dict(json_obj))
7979
except ValidationError as e:
80-
raise APIError(r.json()) from e
81-
except JSONDecodeError:
8280
raise APIError(generate_default_error_message(r))
8381

8482

@@ -124,10 +122,9 @@ def execute(self) -> SingleAPIResponse[_ReturnT]:
124122
): # Response.ok from JS (https://developer.mozilla.org/en-US/docs/Web/API/Response/ok)
125123
return SingleAPIResponse[_ReturnT].from_http_request_response(r)
126124
else:
127-
raise APIError(r.json())
125+
json_obj = APIErrorFromJSON.model_validate_json(r.content)
126+
raise APIError(dict(json_obj))
128127
except ValidationError as e:
129-
raise APIError(r.json()) from e
130-
except JSONDecodeError:
131128
raise APIError(generate_default_error_message(r))
132129

133130

@@ -290,7 +287,7 @@ def select(
290287
*columns: The names of the columns to fetch.
291288
count: The method to use to get the count of rows returned.
292289
Returns:
293-
:class:`SyncSelectRequestBuilder`
290+
:class:`AsyncSelectRequestBuilder`
294291
"""
295292
method, params, headers, json = pre_select(*columns, count=count, head=head)
296293
return SyncSelectRequestBuilder[_ReturnT](
@@ -317,7 +314,7 @@ def insert(
317314
Otherwise, use the default value for the column.
318315
Only applies for bulk inserts.
319316
Returns:
320-
:class:`SyncQueryRequestBuilder`
317+
:class:`AsyncQueryRequestBuilder`
321318
"""
322319
method, params, headers, json = pre_insert(
323320
json,
@@ -353,7 +350,7 @@ def upsert(
353350
not when merging with existing rows under `ignoreDuplicates: false`.
354351
This also only applies when doing bulk upserts.
355352
Returns:
356-
:class:`SyncQueryRequestBuilder`
353+
:class:`AsyncQueryRequestBuilder`
357354
"""
358355
method, params, headers, json = pre_upsert(
359356
json,
@@ -381,7 +378,7 @@ def update(
381378
count: The method to use to get the count of rows returned.
382379
returning: Either 'minimal' or 'representation'
383380
Returns:
384-
:class:`SyncFilterRequestBuilder`
381+
:class:`AsyncFilterRequestBuilder`
385382
"""
386383
method, params, headers, json = pre_update(
387384
json,
@@ -404,7 +401,7 @@ def delete(
404401
count: The method to use to get the count of rows returned.
405402
returning: Either 'minimal' or 'representation'
406403
Returns:
407-
:class:`SyncFilterRequestBuilder`
404+
:class:`AsyncFilterRequestBuilder`
408405
"""
409406
method, params, headers, json = pre_delete(
410407
count=count,

postgrest/base_request_builder.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,11 @@ def select(
660660
"""
661661
method, params, headers, json = pre_select(*columns, count=None)
662662
self.params = self.params.add("select", params.get("select"))
663-
self.headers["Prefer"] = "return=representation"
663+
if self.headers.get("Prefer"):
664+
self.headers["Prefer"] += ",return=representation"
665+
else:
666+
self.headers["Prefer"] = "return=representation"
667+
664668
return self
665669

666670
def single(self) -> Self:

0 commit comments

Comments
 (0)