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

Unbound response error #726

Open
ddematheu opened this issue Mar 13, 2024 · 3 comments
Open

Unbound response error #726

ddematheu opened this issue Mar 13, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ddematheu
Copy link

Bug report

Describe the bug

Library is throwing a unbound error for variable response.

To Reproduce

Call : response = supabase.storage.from_(bucket_name).download(file_path)

Full tracestack

File "/app/supabase_utils/download_utils.py", line 39, in download_with_retry
response = supabase.storage.from_(bucket_name).download(file_path)
File "/usr/local/lib/python3.10/site-packages/storage3/_sync/file_api.py", line 342, in download
response = self._request(
File "/usr/local/lib/python3.10/site-packages/storage3/_sync/file_api.py", line 50, in _request
resp = response.json()
UnboundLocalError: local variable 'response' referenced before assignment"

Expected behavior

A clear and concise description of what you expected to happen.

No unbound error.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

Add any other context about the problem here.

@ddematheu ddematheu added the bug Something isn't working label Mar 13, 2024
@Zeulni
Copy link

Zeulni commented Mar 17, 2024

I have a similar issue with the same call response = supabase.storage.from_(bucket_name).download(file_path)

Suddenly, without any change, I get the error "ERROR: cannot access local variable 'response' where it is not associated with a value"

@ddematheu
Copy link
Author

It was the same with me. No change from my side and starting seeing error.

@Abullity
Copy link

Abullity commented May 8, 2024

I have similar issue.

here's my code:

res = await get_async_client().storage.from_(PDF_BUCKET).upload(
        file=file,
        path=filename,
        file_options={"content-type": "application/pdf"}
    )

    return res.json()

this exception was raised because I was trying to upload PDF greater than 50mb, the handling however is not error-proof, here's the code responsible for the exception:

in storage3/_async/file_api.py:50

async def _request(
        self,
        method: RequestMethod,
        url: str,
        headers: Optional[dict[str, Any]] = None,
        json: Optional[dict[Any, Any]] = None,
        files: Optional[Any] = None,
        **kwargs: Any,
    ) -> Response:
        try:
            response = await self._client.request(
                method, url, headers=headers or {}, json=json, files=files, **kwargs
            )
            response.raise_for_status()
        except HTTPError:
            try:
                resp = response.json()  # <--- this line is responsible for the error 
                raise StorageException({**resp, "statusCode": response.status_code})
            except JSONDecodeError:
                raise StorageException({"statusCode": response.status_code})

        return response

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

No branches or pull requests

3 participants