However when the session is loaded, these default values get overwritten by the data loaded from the backend:
async def load(self) -> None:
"""
Load data from the backend.
Subsequent calls do not take any effect.
"""
if self.is_loaded:
return
if not self.session_id:
self.data = default_session()
else:
self.data = await self._backend.read(self.session_id)
self.is_loaded = True
My solution was to do this instead:
async def load(self) -> None:
"""
Load data from the backend.
Subsequent calls do not take any effect.
"""
if self.is_loaded:
return
if not self.session_id:
self.data = default_session()
else:
# Update data to keep default values
backend_data = await self._backend.read(self.session_id)
backend_data.update(self._data)
self.data = backend_data
This is by design. Backend data has the highest priority. You can implement this feature in a custom backend and override read/write methods to add this extra values.
Not sure if this is a bug, just an issue I encountered when working:
When a session is created, I'm adding a default _created date in the _data field:
However when the session is loaded, these default values get overwritten by the data loaded from the backend:
My solution was to do this instead: