Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paulSerre opened this issue Dec 7, 2024 · 0 comments · May be fixed by #551
Open

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

paulSerre opened this issue Dec 7, 2024 · 0 comments · May be fixed by #551
Labels
bug Something isn't working

Comments

@paulSerre
Copy link
Contributor

paulSerre commented Dec 7, 2024

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
@paulSerre paulSerre added the bug Something isn't working label Dec 7, 2024
paulSerre added a commit to paulSerre/postgrest-py that referenced this issue Dec 7, 2024
@silentworks silentworks linked a pull request Dec 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant