[entity] when .related() is called on a not-yet-saved entity, return an empty rset/list instead of raising an assertion error stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 16 Jun 2010 09:53:17 +0200
branchstable
changeset 5757 e501806ab489
parent 5756 ab03e4adb4f1
child 5758 37968502da70
[entity] when .related() is called on a not-yet-saved entity, return an empty rset/list instead of raising an assertion error
entity.py
--- a/entity.py	Wed Jun 16 09:33:04 2010 +0200
+++ b/entity.py	Wed Jun 16 09:53:17 2010 +0200
@@ -751,7 +751,10 @@
             return self.related_cache(rtype, role, entities, limit)
         except KeyError:
             pass
-        assert self.has_eid()
+        if not self.has_eid():
+            if entities:
+                return []
+            return self.empty_rset()
         rql = self.related_rql(rtype, role)
         rset = self._cw.execute(rql, {'x': self.eid})
         self.set_related_cache(rtype, role, rset)