Skip to content

Commit 1c3a01a

Browse files
mihidumhhayescode
andauthored
fix: data persistence bug introduced in #2433 (#2460)
The Type Checking fix from #2433 introduced a new issue that causes an error while persisting to the database. This PR should fix that while passing mypy checks. if not isinstance(self.storage_client, GCSStorageClient) ^^^^^^^^^^^^^^^^ NameError: name 'GCSStorageClient' is not defined. Did you mean: 'BaseStorageClient'? --------- Co-authored-by: Josh Hayes <[email protected]>
1 parent 78d67ad commit 1c3a01a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

backend/chainlit/data/chainlit_data_layer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
)
2727
from chainlit.user import PersistedUser, User
2828

29+
# Import for runtime usage (isinstance checks)
30+
try:
31+
from chainlit.data.storage_clients.gcs import GCSStorageClient
32+
except ImportError:
33+
GCSStorageClient = None # type: ignore[assignment,misc]
34+
2935
if TYPE_CHECKING:
3036
from chainlit.data.storage_clients.gcs import GCSStorageClient
3137
from chainlit.element import Element, ElementDict
@@ -202,7 +208,10 @@ async def create_element(self, element: "Element"):
202208
if content is not None:
203209
content_disposition = (
204210
f'attachment; filename="{element.name}"'
205-
if not isinstance(self.storage_client, GCSStorageClient)
211+
if not (
212+
GCSStorageClient is not None
213+
and isinstance(self.storage_client, GCSStorageClient)
214+
)
206215
else None
207216
)
208217
await self.storage_client.upload_file(

0 commit comments

Comments
 (0)