server/repository.py
branchstable
changeset 4643 921737d2e3a8
parent 4517 0f3c10fc42b2
child 4673 6f8b925a29f4
--- a/server/repository.py	Thu Feb 18 15:42:29 2010 +0100
+++ b/server/repository.py	Fri Feb 19 09:34:14 2010 +0100
@@ -101,14 +101,11 @@
     this kind of behaviour has to be done in the repository so we don't have
     hooks order hazardness
     """
-    # skip delete queries (only?) if session is an internal session. This is
-    # hooks responsability to ensure they do not violate relation's cardinality
-    if session.is_super_session:
-        return
-    ensure_card_respected(session.unsafe_execute, session, eidfrom, rtype, eidto)
-
-
-def ensure_card_respected(execute, session, eidfrom, rtype, eidto):
+    # XXX now that rql in migraction default to unsafe_execute we don't want to
+    #     skip that anymore. Also we should imo rely on the orm to first fetch
+    #     existing entity if any then delete it
+    #if session.is_super_session:
+    #    return
     card = session.schema_rproperty(rtype, eidfrom, eidto, 'cardinality')
     # one may be tented to check for neweids but this may cause more than one
     # relation even with '1?'  cardinality if thoses relations are added in the
@@ -118,12 +115,12 @@
     # consistency.
     if card[0] in '1?':
         rschema = session.repo.schema.rschema(rtype)
-        if not rschema.inlined:
-            execute('DELETE X %s Y WHERE X eid %%(x)s,NOT Y eid %%(y)s' % rtype,
-                    {'x': eidfrom, 'y': eidto}, 'x')
+        if not rschema.inlined: # inlined relations will be implicitly deleted
+            session.unsafe_execute('DELETE X %s Y WHERE X eid %%(x)s, NOT Y eid %%(y)s' % rtype,
+                                   {'x': eidfrom, 'y': eidto}, 'x')
     if card[1] in '1?':
-        execute('DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype,
-                {'x': eidfrom, 'y': eidto}, 'y')
+        session.unsafe_execute('DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype,
+                               {'x': eidfrom, 'y': eidto}, 'y')
 
 
 class Repository(object):