Closed
Description
Using supabase python API client, if you want to perform a count on a query without querying for result (i.e head=True), you'll get an empty array and a count equals to 0.
Try it out:
select("*", head=True, count="exact")
This is because when Head=True, you use HEAD as http request method. Consequently, the result won't have a json, so this method will throw a JSONDecodeError:
@classmethod
def from_http_request_response(
cls: Type[Self], request_response: RequestResponse
) -> Self:
try:
data = request_response.json()
except JSONDecodeError:
return cls(data=[], count=0)
count = cls._get_count_from_http_request_response(request_response)
# the type-ignore here is as pydantic needs us to pass the type parameter
# here explicitly, but pylance already knows that cls is correctly parametrized
return cls[_ReturnT](data=data, count=count) # type: ignore
In think we should just assign data to an empty array if an error occurs:
@classmethod
def from_http_request_response(
cls: Type[Self], request_response: RequestResponse
) -> Self:
try:
data = request_response.json()
except JSONDecodeError:
data = []
count = cls._get_count_from_http_request_response(request_response)
# the type-ignore here is as pydantic needs us to pass the type parameter
# here explicitly, but pylance already knows that cls is correctly parametrized
return cls[_ReturnT](data=data, count=count) # type: ignore