Skip to content

Commit

Permalink
maybe_single with no matching rows returns None (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
anand2312 committed Mar 7, 2023
1 parent 67572ba commit d148298
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
10 changes: 2 additions & 8 deletions postgrest/_async/request_builder.py
Expand Up @@ -122,19 +122,13 @@ async def execute(self) -> SingleAPIResponse:


class AsyncMaybeSingleRequestBuilder(AsyncSingleRequestBuilder):
async def execute(self) -> SingleAPIResponse:
async def execute(self) -> Optional[SingleAPIResponse]:
r = None
try:
r = await super().execute()
except APIError as e:
if e.details and "Results contain 0 rows" in e.details:
return SingleAPIResponse.from_dict(
{
"data": None,
"error": None,
"count": 0, # NOTE: needs to take value from res.count
}
)
return None
if not r:
raise APIError(
{
Expand Down
10 changes: 2 additions & 8 deletions postgrest/_sync/request_builder.py
Expand Up @@ -122,19 +122,13 @@ def execute(self) -> SingleAPIResponse:


class SyncMaybeSingleRequestBuilder(SyncSingleRequestBuilder):
def execute(self) -> SingleAPIResponse:
def execute(self) -> Optional[SingleAPIResponse]:
r = None
try:
r = super().execute()
except APIError as e:
if e.details and "Results contain 0 rows" in e.details:
return SingleAPIResponse.from_dict(
{
"data": None,
"error": None,
"count": 0, # NOTE: needs to take value from res.count
}
)
return None
if not r:
raise APIError(
{
Expand Down

0 comments on commit d148298

Please sign in to comment.