[repository] don't attempt to delete computed relation, they have no table in the database. Closes #5162935
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 25 Mar 2015 07:57:38 +0100
changeset 10285 d14db30b90d6
parent 10284 fb113f9fa7d8
child 10286 0f8c3ac88f1e
[repository] don't attempt to delete computed relation, they have no table in the database. Closes #5162935
server/repository.py
server/test/data/schema.py
server/test/unittest_repository.py
--- a/server/repository.py	Mon Mar 23 14:28:48 2015 +0100
+++ b/server/repository.py	Wed Mar 25 07:57:38 2015 +0100
@@ -1095,6 +1095,8 @@
         with session.security_enabled(read=False, write=False):
             eid = entity.eid
             for rschema, _, role in entity.e_schema.relation_definitions():
+                if rschema.rule:
+                    continue # computed relation
                 rtype = rschema.type
                 if rtype in schema.VIRTUAL_RTYPES or rtype in pendingrtypes:
                     continue
@@ -1123,6 +1125,8 @@
         with session.security_enabled(read=False, write=False):
             in_eids = ','.join([str(_e.eid) for _e in entities])
             for rschema, _, role in entities[0].e_schema.relation_definitions():
+                if rschema.rule:
+                    continue # computed relation
                 rtype = rschema.type
                 if rtype in schema.VIRTUAL_RTYPES or rtype in pendingrtypes:
                     continue
--- a/server/test/data/schema.py	Mon Mar 23 14:28:48 2015 +0100
+++ b/server/test/data/schema.py	Wed Mar 25 07:57:38 2015 +0100
@@ -16,7 +16,7 @@
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 
-from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
+from yams.buildobjs import (EntityType, RelationType, RelationDefinition, ComputedRelation,
                             SubjectRelation, RichString, String, Int, Float,
                             Boolean, Datetime, TZDatetime, Bytes)
 from yams.constraints import SizeConstraint
@@ -274,3 +274,7 @@
     object = 'CWUser'
     inlined = True
     cardinality = '?*'
+
+
+class user_login(ComputedRelation):
+    rule = 'O login_user S'
--- a/server/test/unittest_repository.py	Mon Mar 23 14:28:48 2015 +0100
+++ b/server/test/unittest_repository.py	Wed Mar 25 07:57:38 2015 +0100
@@ -499,6 +499,13 @@
             cnx.commit()
             self.assertEqual(len(c.reverse_fiche), 1)
 
+    def test_delete_computed_relation_nonregr(self):
+        with self.admin_access.repo_cnx() as cnx:
+            c = cnx.create_entity('Personne', nom=u'Adam', login_user=cnx.user.eid)
+            cnx.commit()
+            c.cw_delete()
+            cnx.commit()
+
     def test_cw_set_in_before_update(self):
         # local hook
         class DummyBeforeHook(Hook):