Skip to content

Commit d9d3d31

Browse files
committed
Fix DictView and broken account access on remote
1 parent e40fa3b commit d9d3d31

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

src/daf/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async def schema_load_from_file() -> None:
142142

143143
trace("Restoring objects from file...", TraceLEVELS.NORMAL)
144144
with open(SHILL_LIST_BACKUP_PATH, "rb") as reader:
145-
accounts = convert.convert_from_semi_dict(pickle.load(reader))
145+
accounts: List[client.ACCOUNT] = convert.convert_from_semi_dict(pickle.load(reader))
146146

147147
trace("Updating accounts.", TraceLEVELS.DEBUG)
148148
for account in accounts:
@@ -156,6 +156,8 @@ async def schema_load_from_file() -> None:
156156
TraceLEVELS.ERROR, exc
157157
)
158158
finally:
159+
# Save ID regardless if we failed result otherwise we cannot access though remote
160+
account._update_tracked_id()
159161
GLOBALS.accounts.append(account)
160162

161163
trace(f"Restored objects from file ({len(GLOBALS.accounts)} accounts).", TraceLEVELS.NORMAL)

src/daf/misc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,15 @@ class TrackedClass(cls):
261261
if hasattr(cls, "__slots__"): # Don't break classes without slots
262262
__slots__ = ("__weakref__", "_daf_id")
263263

264-
async def initialize(self, *args, **kwargs):
265-
_r = await super().initialize(*args, **kwargs)
266-
# Update weakref dictionary
264+
def _update_tracked_id(self):
265+
"Saves ID to the tracked dictionary"
267266
value = id(self)
268267
self._daf_id = value
269268
OBJECT_ID_MAP[value] = self
269+
270+
async def initialize(self, *args, **kwargs):
271+
_r = await super().initialize(*args, **kwargs)
272+
self._update_tracked_id()
270273
return _r
271274

272275
def __getattr__(self, __key: str):

src/daf_gui/convert.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -471,18 +471,23 @@ def __init__(self) -> None:
471471
annotations = {}
472472
object_info_data = {}
473473

474-
for k, v in data.items():
475-
if isinstance(v, dict):
476-
v = convert_dict_to_object_info(v)
477-
type_v = type(v)
478-
elif isinstance(v, Iterable) and not isinstance(v, str):
479-
v = [convert_dict_to_object_info(item) for item in v]
480-
type_v = List[Any]
481-
else:
482-
type_v = type(v)
474+
if isinstance(data, dict):
475+
for k, v in data.items():
476+
if isinstance(v, dict):
477+
v = convert_dict_to_object_info(v)
478+
type_v = type(v)
479+
elif isinstance(v, (list, tuple, set)):
480+
v = convert_dict_to_object_info(v)
481+
type_v = List[Any]
482+
else:
483+
type_v = type(v)
483484

484-
annotations[k] = type_v
485-
object_info_data[k] = v
485+
annotations[k] = type_v
486+
object_info_data[k] = v
486487

487-
DictView.__init__.__annotations__ = annotations
488-
return ObjectInfo(DictView, object_info_data)
488+
DictView.__init__.__annotations__ = annotations
489+
return ObjectInfo(DictView, object_info_data)
490+
elif isinstance(data, (list, tuple, set)):
491+
return [convert_dict_to_object_info(x) for x in data]
492+
else:
493+
return data

0 commit comments

Comments
 (0)