From f00c6f2f498783f8aa6431d64918c535e18a7f84 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Sat, 16 Jun 2018 15:33:56 +0200 Subject: [PATCH] Fix syncing for Add/remove --- ereuse_devicehub/resources/event/models.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/resources/event/models.py b/ereuse_devicehub/resources/event/models.py index b6d63a4b..0036515c 100644 --- a/ereuse_devicehub/resources/event/models.py +++ b/ereuse_devicehub/resources/event/models.py @@ -98,6 +98,9 @@ class Event(Thing): For example: an ``Allocate`` is performed to a Computer and this relationship is filled with the components the computer had at the time of the event. + + For Add and Remove though, this has another meaning: the components + that are added or removed. """ parent_id = Column(BigInteger, ForeignKey(Computer.id)) parent = relationship(Computer, @@ -438,9 +441,12 @@ def update_components_event_one(target: EventWithOneDevice, device: Device, __, Syncs the :attr:`.Event.components` with the components in :attr:`ereuse_devicehub.resources.device.models.Computer.components`. """ - target.components.clear() - if isinstance(device, Computer): - target.components |= device.components + # For Add and Remove, ``components`` have different meanings + # see Event.components for more info + if not isinstance(target, (Add, Remove)): + target.components.clear() + if isinstance(device, Computer): + target.components |= device.components @event.listens_for(EventWithMultipleDevices.devices, Events.init_collection.__name__,