server/hooks.py
changeset 2605 c4f6a53884ec
parent 2603 e47d63351891
child 2606 598ac51cac04
--- a/server/hooks.py	Fri Jul 31 23:45:07 2009 +0200
+++ b/server/hooks.py	Fri Jul 31 23:46:59 2009 +0200
@@ -17,6 +17,15 @@
                                      get_user_sessions, rproperty)
 from cubicweb.server.repository import FTIndexEntityOp
 
+# special relations that don't have to be checked for integrity, usually
+# because they are handled internally by hooks (so we trust ourselves)
+DONT_CHECK_RTYPES_ON_ADD = set(('owned_by', 'created_by',
+                                'is', 'is_instance_of',
+                                'wf_info_for', 'from_state', 'to_state'))
+DONT_CHECK_RTYPES_ON_DEL = set(('is', 'is_instance_of',
+                                'wf_info_for', 'from_state', 'to_state'))
+
+
 def relation_deleted(session, eidfrom, rtype, eidto):
     session.transaction_data.setdefault('pendingrelations', []).append(
         (eidfrom, rtype, eidto))
@@ -280,7 +289,7 @@
     eid = entity.eid
     for rschema, targetschemas, x in entity.e_schema.relation_definitions():
         # skip automatically handled relations
-        if rschema.type in ('owned_by', 'created_by', 'is', 'is_instance_of'):
+        if rschema.type in DONT_CHECK_RTYPES_ON_ADD:
             continue
         if x == 'subject':
             subjtype = entity.e_schema
@@ -299,6 +308,8 @@
 
 def cardinalitycheck_before_del_relation(session, eidfrom, rtype, eidto):
     """check cardinalities are satisfied"""
+    if rtype in DONT_CHECK_RTYPES_ON_DEL:
+        return
     card = rproperty(session, rtype, eidfrom, eidto, 'cardinality')
     pendingeids = session.transaction_data.get('pendingeids', ())
     if card[0] in '1+' and not eidfrom in pendingeids: