From 870329f2de0e0110e265a753ef5cb270c09333dd Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Mon, 20 Feb 2023 17:44:34 +0000 Subject: [PATCH] Context component: - Corrected method UnsetSlice to remove constraints --- src/context/service/database/Constraint.py | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/context/service/database/Constraint.py b/src/context/service/database/Constraint.py index 5ebe36f99..3a73f6589 100644 --- a/src/context/service/database/Constraint.py +++ b/src/context/service/database/Constraint.py @@ -86,26 +86,24 @@ def upsert_constraints( ) -> bool: uuids_to_upsert : Dict[str, int] = dict() rules_to_upsert : List[Dict] = list() - if not is_delete: - for constraint in constraints: - constraint_uuid = constraint['constraint_uuid'] - position = uuids_to_upsert.get(constraint_uuid) - if position is None: - # if not added, add it - rules_to_upsert.append(constraint) - uuids_to_upsert[constraint_uuid] = len(rules_to_upsert) - 1 - else: - # if already added, update occurrence - rules_to_upsert[position] = constraint + for constraint in constraints: + constraint_uuid = constraint['constraint_uuid'] + position = uuids_to_upsert.get(constraint_uuid) + if position is None: + # if not added, add it + rules_to_upsert.append(constraint) + uuids_to_upsert[constraint_uuid] = len(rules_to_upsert) - 1 + else: + # if already added, update occurrence + rules_to_upsert[position] = constraint # Delete all constraints not in uuids_to_upsert delete_affected = False - if is_delete or len(uuids_to_upsert) > 0: + if len(uuids_to_upsert) > 0: stmt = delete(ConstraintModel) if service_uuid is not None: stmt = stmt.where(ConstraintModel.service_uuid == service_uuid) if slice_uuid is not None: stmt = stmt.where(ConstraintModel.slice_uuid == slice_uuid ) - if not is_delete: - stmt = stmt.where(ConstraintModel.constraint_uuid.not_in(set(uuids_to_upsert.keys()))) + stmt = stmt.where(ConstraintModel.constraint_uuid.not_in(set(uuids_to_upsert.keys()))) #str_stmt = stmt.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}) #LOGGER.warning('delete stmt={:s}'.format(str(str_stmt))) constraint_deletes = session.execute(stmt) -- GitLab