Skip to content

Commit d568896

Browse files
committed
app.storage.tab is only persistent when using Redis
This allows storing non-serializable data in "normal" circumstances.
1 parent 09d0d56 commit d568896

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

nicegui/storage.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Storage:
6666
def __init__(self) -> None:
6767
self._general = Storage._create_persistent_dict('general')
6868
self._users: Dict[str, PersistentDict] = {}
69-
self._tabs: Dict[str, PersistentDict] = {}
69+
self._tabs: Dict[str, ObservableDict] = {}
7070

7171
@staticmethod
7272
def _create_persistent_dict(id: str) -> PersistentDict: # pylint: disable=redefined-builtin
@@ -163,13 +163,19 @@ def tab(self) -> observables.ObservableDict:
163163
async def _create_tab_storage(self, tab_id: str) -> None:
164164
"""Create tab storage for the given tab ID."""
165165
if tab_id not in self._tabs:
166-
self._tabs[tab_id] = Storage._create_persistent_dict(f'tab-{tab_id}')
167-
await self._tabs[tab_id].initialize()
166+
if Storage.redis_url:
167+
self._tabs[tab_id] = Storage._create_persistent_dict(f'tab-{tab_id}')
168+
await self._tabs[tab_id].initialize()
169+
else:
170+
self._tabs[tab_id] = ObservableDict()
168171

169172
def copy_tab(self, old_tab_id: str, tab_id: str) -> None:
170173
"""Copy the tab storage to a new tab. (For internal use only.)"""
171174
if old_tab_id in self._tabs:
172-
self._tabs[tab_id] = Storage._create_persistent_dict(f'tab-{tab_id}')
175+
if Storage.redis_url:
176+
self._tabs[tab_id] = Storage._create_persistent_dict(f'tab-{tab_id}')
177+
else:
178+
self._tabs[tab_id] = ObservableDict()
173179
self._tabs[tab_id].update(self._tabs[old_tab_id])
174180

175181
async def prune_tab_storage(self) -> None:

0 commit comments

Comments
 (0)