supabase-community / storage-py

Home Page:https://supabase-community.github.io/storage-py/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug in list_buckets it onprem env

arbela-cyberillium opened this issue · comments

Describe the bug
In onprem (docker compose up) we get an error when listing buckets

In [7]: storage.list_buckets()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [7], line 1
----> 1 storage.list_buckets()

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\storage3\_sync\bucket.py:40, in SyncStorageBucketAPI.list_buckets(self)
     38 # if the request doesn't error, it is assured to return a list
     39 res = self._request("GET", "/bucket")
---> 40 return [SyncBucket(**bucket, _client=self._client) for bucket in res.json()]

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\storage3\_sync\bucket.py:40, in <listcomp>(.0)
     38 # if the request doesn't error, it is assured to return a list
     39 res = self._request("GET", "/bucket")
---> 40 return [SyncBucket(**bucket, _client=self._client) for bucket in res.json()]
TypeError: SyncBucket.__init__() missing 2 required positional arguments: 'file_size_limit' and 'allowed_mime_types'

Solotion
We are not using file_size_limit or allowed_mime_types in the code (or in supabase-py code) so we can make them optional.

file: types.py

@dataclass
class BaseBucket:
    """Represents a file storage bucket."""

    id: str
    name: str
    owner: str
    public: bool
    created_at: datetime
    updated_at: datetime
    file_size_limit: int | None = None
    allowed_mime_types: str | None = None

or

file: types.py

@dataclass
class BaseBucket:
    """Represents a file storage bucket."""

    id: str
    name: str
    owner: str
    public: bool
    created_at: datetime
    updated_at: datetime
    file_size_limit: int = 0
    allowed_mime_types: str = ""
commented

this is odd - the storage API docs seem to suggest that it will send values for file_size_limit and allowed_mime_types. Are you perhaps self-hosting an older version of supabase? In that case you'd be forced to use an older version of the library as well (or update the version of supabase) 😦
Setting the default value errors out because we inherit from BaseBucket and set non-default fields later and non-default fields cannot follow default fields