fix bug drop parents

This commit is contained in:
Cayo Puigdefabregas 2023-08-01 15:00:31 +02:00
parent 1941f28ab3
commit 3a1f135310
1 changed files with 11 additions and 0 deletions

View File

@ -92,10 +92,21 @@ class Sync:
# We only want to perform Add/Remove to not new components # We only want to perform Add/Remove to not new components
actions = self.add_remove(db_device, not_new_components) actions = self.add_remove(db_device, not_new_components)
db_device.components = db_components db_device.components = db_components
self.clean_parent_orphans_components(db_device)
self.create_placeholder(db_device) self.create_placeholder(db_device)
return db_device, actions return db_device, actions
def clean_parent_orphans_components(self, device):
all_components = Component.query.filter_by(parent_id=device.id)
for _c in all_components:
if _c not in device.components:
_c.parent = None
if _c.binding:
_c.binding.device.parent = None
if _c.placeholder and _c.placeholder.binding:
_c.placeholder.binding.parent = None
def execute_register_component(self, component: Component): def execute_register_component(self, component: Component):
"""Synchronizes one component to the DB. """Synchronizes one component to the DB.