[entity] put cached related entities as tuple to be sure no one is modifying stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 02 Oct 2009 14:17:22 +0200
branchstable
changeset 3552 8facb3324170
parent 3551 5a73db781dac
child 3553 76b4a177a018
[entity] put cached related entities as tuple to be sure no one is modifying
entity.py
--- a/entity.py	Fri Oct 02 14:15:23 2009 +0200
+++ b/entity.py	Fri Oct 02 14:17:22 2009 +0200
@@ -804,7 +804,7 @@
         else raise `KeyError`
         """
         res = self._related_cache['%s_%s' % (rtype, role)][entities]
-        if limit:
+        if limit is not None:
             if entities:
                 res = res[:limit]
             else:
@@ -814,7 +814,7 @@
     def set_related_cache(self, rtype, role, rset, col=0):
         """set cached values for the given relation"""
         if rset:
-            related = list(rset.entities(col))
+            related = tuple(rset.entities(col))
             rschema = self.schema.rschema(rtype)
             if role == 'subject':
                 rcard = rschema.rproperty(self.e_schema, related[0].e_schema,
@@ -826,9 +826,10 @@
                 target = 'subject'
             if rcard in '?1':
                 for rentity in related:
-                    rentity._related_cache['%s_%s' % (rtype, target)] = (self.as_rset(), [self])
+                    rentity._related_cache['%s_%s' % (rtype, target)] = (
+                        self.as_rset(), (self,))
         else:
-            related = []
+            related = ()
         self._related_cache['%s_%s' % (rtype, role)] = (rset, related)
 
     def clear_related_cache(self, rtype=None, role=None):