Skip to content

select("*", head=True, count="exact") will only return empty data with 0 count #544

Closed
@paulSerre

Description

@paulSerre

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions