Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/postgrest/src/postgrest/_async/request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ async def execute(self) -> APIResponse:
try:
if r.is_success:
return APIResponse.from_http_request_response(r)
elif not r.content:
raise APIError(generate_default_error_message(r))
else:
json_obj = model_validate_json(APIErrorFromJSON, r.content)
raise APIError(dict(json_obj))
Expand Down
2 changes: 2 additions & 0 deletions src/postgrest/src/postgrest/_sync/request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def execute(self) -> APIResponse:
try:
if r.is_success:
return APIResponse.from_http_request_response(r)
elif not r.content:
raise APIError(generate_default_error_message(r))
else:
json_obj = model_validate_json(APIErrorFromJSON, r.content)
raise APIError(dict(json_obj))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

import pytest

from postgrest import CountMethod
Expand Down Expand Up @@ -640,6 +642,22 @@ async def test_rpc_head_count():
assert res.count == 2
assert res.data == []

async def test_head_query_error():
with patch(
"postgrest._async.request_builder.model_validate_json"
) as mock_validate:
with pytest.raises(APIError) as exc_info:
await (
rest_client()
.from_("countries")
.select("*", count=CountMethod.exact, head=True)
.eq("ref.othercol", 123)
.execute()
)

mock_validate.assert_not_called()
assert exc_info.value.code == 400


async def test_order():
res = (
Expand Down