fix sync
This commit is contained in:
parent
fc36218124
commit
2cc677a555
|
@ -67,9 +67,10 @@ 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).
|
||||||
"""
|
"""
|
||||||
device.components = OrderedSet(components)
|
if components:
|
||||||
device.set_hid()
|
device.components = OrderedSet(components)
|
||||||
device.components = OrderedSet()
|
device.set_hid()
|
||||||
|
device.components = OrderedSet()
|
||||||
db_device = self.execute_register(device)
|
db_device = self.execute_register(device)
|
||||||
|
|
||||||
db_components, actions = OrderedSet(), OrderedSet()
|
db_components, actions = OrderedSet(), 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),
|
||||||
|
|
Reference in New Issue