Skip to content

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

Closed
@RafayAK

Description

@RafayAK

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)

Metadata

Metadata

Assignees

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