Skip to content

Commit 3f349dc

Browse files
committed
fix: Prevent caching unpicklable trait objects
DeviceFeaturesTrait and NetworkInfoTrait were storing entire trait objects (including unpicklable _rpc_channel) in the cache, causing pickle errors during cache.flush(). Now creates pure data-only instances for caching, excluding runtime objects like _rpc_channel, _device_cache, and _nickname. Fixes: AttributeError when flushing cache - "Can't pickle local object 'V1Channel.rpc_channel.<locals>.rpc_strategies_cb'"
1 parent c843ab6 commit 3f349dc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

roborock/devices/traits/v1/device_features.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ async def refresh(self) -> None:
3434
return
3535
# Save cached device features
3636
await super().refresh()
37-
cache_data.device_features = self
37+
# Create a pure DeviceFeatures instance without runtime objects
38+
device_features_data = DeviceFeatures()
39+
for field in fields(DeviceFeatures):
40+
setattr(device_features_data, field.name, getattr(self, field.name))
41+
cache_data.device_features = device_features_data
3842
await self._device_cache.set(cache_data)
3943

4044
def _parse_response(self, response: common.V1ResponseData) -> DeviceFeatures:

roborock/devices/traits/v1/network_info.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import logging
6+
from dataclasses import fields
67

78
from roborock.data import NetworkInfo
89
from roborock.devices.cache import DeviceCache
@@ -45,7 +46,11 @@ async def refresh(self) -> None:
4546

4647
# Update the cache with the new network info
4748
device_cache_data = await self._device_cache.get()
48-
device_cache_data.network_info = self
49+
# Create a pure NetworkInfo instance without runtime objects
50+
network_info_data = NetworkInfo(ip="")
51+
for field in fields(NetworkInfo):
52+
setattr(network_info_data, field.name, getattr(self, field.name))
53+
device_cache_data.network_info = network_info_data
4954
await self._device_cache.set(device_cache_data)
5055

5156
def _parse_response(self, response: common.V1ResponseData) -> NetworkInfo:

0 commit comments

Comments
 (0)