aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_db
diff options
context:
space:
mode:
authorasteroide <thomas.duval@orange.com>2017-06-01 11:43:11 +0200
committerasteroide <thomas.duval@orange.com>2017-06-01 11:43:11 +0200
commit3643c5376b9e4d55c5718c9bd03c692ece2eb5cb (patch)
tree4f000f272fb21b2ad44a82ba314abd8b04377650 /moonv4/moon_db
parent1f38c2e011df775e3fac1c0200df6e7fea43f25c (diff)
Do not add assignment if it already exists.
Change-Id: Ic73d9db4823368bc8fb5f71b2b9b29af3d3ea1c7
Diffstat (limited to 'moonv4/moon_db')
-rw-r--r--moonv4/moon_db/moon_db/backends/sql.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/moonv4/moon_db/moon_db/backends/sql.py b/moonv4/moon_db/moon_db/backends/sql.py
index b9ff332c..d6becbbe 100644
--- a/moonv4/moon_db/moon_db/backends/sql.py
+++ b/moonv4/moon_db/moon_db/backends/sql.py
@@ -820,8 +820,9 @@ class PolicyConnector(BaseConnector, PolicyDriver):
if ref:
old_ref = copy.deepcopy(ref.to_dict())
assignments = old_ref["assignments"]
- assignments.append(data_id)
- setattr(ref, "assignments", assignments)
+ if data_id not in assignments:
+ assignments.append(data_id)
+ setattr(ref, "assignments", assignments)
else:
ref = SubjectAssignment.from_dict(
{
@@ -871,8 +872,9 @@ class PolicyConnector(BaseConnector, PolicyDriver):
if ref:
old_ref = copy.deepcopy(ref.to_dict())
assignments = old_ref["assignments"]
- assignments.append(data_id)
- setattr(ref, "assignments", assignments)
+ if data_id not in assignments:
+ assignments.append(data_id)
+ setattr(ref, "assignments", assignments)
else:
ref = ObjectAssignment.from_dict(
{
@@ -922,9 +924,9 @@ class PolicyConnector(BaseConnector, PolicyDriver):
if ref:
old_ref = copy.deepcopy(ref.to_dict())
assignments = old_ref["assignments"]
- assignments.append(data_id)
- # FIXME (asteroide): the setattr doesn't work here ; the assignments is not updated in the database
- setattr(ref, "assignments", assignments)
+ if data_id not in assignments:
+ assignments.append(data_id)
+ setattr(ref, "assignments", assignments)
else:
ref = ActionAssignment.from_dict(
{