Skip to content

Incorrect return type of Response on upload method from supabase.storage.from_ #1016

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

Closed
2 tasks done
RafayAK opened this issue Dec 23, 2024 · 0 comments · Fixed by #1000
Closed
2 tasks done

Incorrect return type of Response on upload method from supabase.storage.from_ #1016

RafayAK opened this issue Dec 23, 2024 · 0 comments · Fixed by #1000
Assignees
Labels
bug Something isn't working

Comments

@RafayAK
Copy link

RafayAK commented Dec 23, 2024

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

The upload method coming supabase.storage.from_ has the return type of Response in the storage3/_sync/file_api.py:

# excerpt from file_api.py

    def upload(
        self,
        path: str,
        file: Union[BufferedReader, bytes, FileIO, str, Path],
        file_options: Optional[FileOptions] = None,
    ) -> Response:  <<<<<<<<<<< THIS
        """
        Uploads a file to an existing bucket.

        Parameters
        ----------
        path
            The relative file path including the bucket ID. Should be of the format `bucket/folder/subfolder/filename.png`.
            The bucket must already exist before attempting to upload.
        file
            The File object to be stored in the bucket. or a async generator of chunks
        file_options
            HTTP headers.
        """
        return self._upload_or_update("POST", path, file, file_options)

While the method _upload_or_update returns an UploadResponse type object :

# excerpt from file_api.py

    def _upload_or_update(
        self,
        method: Literal["POST", "PUT"],
        path: str,
        file: Union[BufferedReader, bytes, FileIO, str, Path],
        file_options: Optional[FileOptions] = None,
    ) -> UploadResponse:  <<<<<<<< THIS
        """
        Uploads a file to an existing bucket.

        Parameters
        ----------
        path
            The relative file path including the bucket ID. Should be of the format `bucket/folder/subfolder/filename.png`.
            The bucket must already exist before attempting to upload.
        file
            The File object to be stored in the bucket. or a async generator of chunks
        file_options
            HTTP headers.
        """

To Reproduce

This inconsistency breaks some of the code in tutorials where for example a 200 response is being checked on a Response type object here . For example:

from supabase import create_client, Client

SUPABASE_URL = os.getenv('SUPABASE_URL')
SUPABASE_KEY = os.getenv('SUPABASE_KEY')
SUPABASE_BUCKET = os.getenv('SUPABASE_BUCKET')


# Initialize Supabase client
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)

res = supabase.storage.from_(SUPABASE_BUCKET).upload(image_filename, file_content)
if res.status_code == 200:   # <<<<<<<< THIS WILL THROW AN ERROR `AttributeError: 'UploadResponse' object has no attribute 'status_code'`

    print("success!")

Expected behavior

The correct HTTP Response type should be returned with the relevant attributes.

Screenshots

I can provide a screenshot but I think I've debugged where the error is coming from.

System information

  • OS: Fedora Linux 41
  • Version of supabase-py: supabase~=2.10.0 (installed uv add supabase)
@RafayAK RafayAK added the bug Something isn't working label Dec 23, 2024
@silentworks silentworks self-assigned this Dec 24, 2024
@silentworks silentworks linked a pull request Dec 30, 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.

2 participants