From 8ca8f490fab19f52fc729e5ba06456e567922056 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 1 Nov 2020 01:52:56 -0400 Subject: [PATCH] JSONify ModelItemDeleted.ids for QML if needed If a model has tuple keys, these already get turned into JSON strings for the ModelItemSet pyotherside event (for QML and JS reasons). Do the same for ModelItemDeleted's ids field, else the QML event handler will be unable to find the items by IDs. --- src/backend/models/model.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/models/model.py b/src/backend/models/model.py index 59bb0c73..d4e2b6da 100644 --- a/src/backend/models/model.py +++ b/src/backend/models/model.py @@ -11,6 +11,7 @@ from typing import ( from sortedcontainers import SortedList from ..pyotherside_events import ModelCleared, ModelItemDeleted, ModelItemSet +from ..utils import serialize_value_for_qml from . import SyncId if TYPE_CHECKING: @@ -150,7 +151,8 @@ class Model(MutableMapping): if self.sync_id: if self._active_batch_removed is None: - ModelItemDeleted(self.sync_id, index, 1, (item.id,)) + i = serialize_value_for_qml(item.id, json_list_dicts=True) + ModelItemDeleted(self.sync_id, index, 1, (i,)) else: self._active_batch_removed.append((index, item.id)) @@ -199,12 +201,15 @@ class Model(MutableMapping): itertools.groupby(batch, key=lambda x: x[0]) ] + def serialize_id(id_): + return serialize_value_for_qml(id_, json_list_dicts=True) + for group in groups: ModelItemDeleted( self.sync_id, index = group[0][0], count = len(group), - ids = [item[1] for item in group], + ids = [serialize_id(item[1]) for item in group], ) self._active_batch_removed = None