From a176f597405241c50cf20ac3bad468a761c2476f Mon Sep 17 00:00:00 2001 From: Paul Serre Date: Sat, 7 Dec 2024 17:53:54 -0300 Subject: [PATCH] fix #544: head=True triggers JSONDecodeError in from_http_request_response --- postgrest/base_request_builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgrest/base_request_builder.py b/postgrest/base_request_builder.py index b86d8f2..c420645 100644 --- a/postgrest/base_request_builder.py +++ b/postgrest/base_request_builder.py @@ -207,11 +207,11 @@ def _get_count_from_http_request_response( def from_http_request_response( cls: Type[Self], request_response: RequestResponse ) -> Self: + count = cls._get_count_from_http_request_response(request_response) try: data = request_response.json() except JSONDecodeError: - return cls(data=[], count=0) - count = cls._get_count_from_http_request_response(request_response) + data = request_response.text if len(request_response.text) > 0 else [] # 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