This commit is contained in:
Cayo Puigdefabregas 2022-12-14 11:42:11 +01:00
parent fc36218124
commit 2cc677a555
1 changed files with 8 additions and 9 deletions

View File

@ -67,6 +67,7 @@ class Sync:
of the passed-in components. of the passed-in components.
2. A list of Add / Remove (not yet added to session). 2. A list of Add / Remove (not yet added to session).
""" """
if components:
device.components = OrderedSet(components) device.components = OrderedSet(components)
device.set_hid() device.set_hid()
device.components = OrderedSet() device.components = OrderedSet()
@ -113,7 +114,6 @@ class Sync:
- A flag stating if the device is new or it already - A flag stating if the device is new or it already
existed in the DB. existed in the DB.
""" """
# if device.serial_number == 'b8oaas048286':
assert inspect(component).transient, 'Component should not be synced from DB' assert inspect(component).transient, 'Component should not be synced from DB'
# if not is a DataStorage, then need build a new one # if not is a DataStorage, then need build a new one
if component.t in DEVICES_ALLOW_DUPLICITY: if component.t in DEVICES_ALLOW_DUPLICITY:
@ -121,15 +121,14 @@ class Sync:
is_new = True is_new = True
return component, is_new return component, is_new
db_component = None
if component.hid: if component.hid:
db_component = Device.query.filter_by( db_component = Device.query.filter_by(
hid=component.hid, owner_id=g.user.id, placeholder=None hid=component.hid, owner_id=g.user.id, placeholder=None
).first() ).first()
assert isinstance(db_component, Device), '{} must be a component'.format(
db_component
)
is_new = False is_new = False
else: if not db_component:
db.session.add(component) db.session.add(component)
db_component = component db_component = component
is_new = True is_new = True
@ -177,7 +176,7 @@ class Sync:
# Manage 'one tag per organization' unique constraint # Manage 'one tag per organization' unique constraint
if 'One tag per organization' in e.args[0]: if 'One tag per organization' in e.args[0]:
# todo test for this # todo test for this
id = int(e.args[0][135 : e.args[0].index(',', 135)]) id = int(e.args[0][135 : e.args[0].index(',', 135)]) # noqa: E203
raise ValidationError( raise ValidationError(
'The device is already linked to tag {} ' 'The device is already linked to tag {} '
'from the same organization.'.format(id), 'from the same organization.'.format(id),