Reviewers: ,


Please review this at http://codereview.tryton.org/370002/

Affected files:
  M tryton/gui/window/view_form/model/group.py
  M tryton/gui/window/view_form/model/record.py


Index: tryton/gui/window/view_form/model/group.py
===================================================================

--- a/tryton/gui/window/view_form/model/group.py
+++ b/tryton/gui/window/view_form/model/group.py
@@ -1,5 +1,10 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
+try:
+    from weakref import WeakSet
+except ImportError:
+    from weakrefset import WeakSet
+
 from record import Record
 from field import Field, O2MField
 from tryton.signal_event import SignalEvent
@@ -36,6 +41,7 @@
         self.__id2record = {}
         self.__field_childs = None
         self.exclude_field = None
+        self.pool = WeakSet()

     @property
     def domain(self):

Index: tryton/gui/window/view_form/model/record.py
===================================================================

--- a/tryton/gui/window/view_form/model/record.py
+++ b/tryton/gui/window/view_form/model/record.py
@@ -1,10 +1,5 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
-try:
-    from weakref import WeakSet
-except ImportError:
-    from weakrefset import WeakSet
-from collections import defaultdict
 import tryton.rpc as rpc
 from tryton.signal_event import SignalEvent
 import tryton.common as common
@@ -13,8 +8,6 @@
 from functools import reduce
 from tryton.common import RPCExecute, RPCException

-POOL = defaultdict(WeakSet)
-

 class Record(SignalEvent):

@@ -42,7 +35,7 @@
         self.autocompletion = {}
         self.exception = False
         self.destroyed = False
-        POOL[model_name].add(self)
+        self.pool.add(self)

     def __getitem__(self, name):
         if name not in self._loaded and self.id >= 0:
@@ -74,7 +67,7 @@
                     n += 1
             record_context = self.context_get()
             if loading == 'eager' and len(id2record) < 80:
-                for record in POOL[self.model_name]:
+                for record in self.pool:
                     if (name not in record._loaded
                             and record.id >= 0
                             and record.id not in id2record
@@ -132,6 +125,14 @@
         return bool(self.modified_fields)

     @property
+    def pool(self):
+        group = self.group
+        while (group.parent is not None
+                and group.parent.model_name == self.model_name):
+            group = group.parent
+        return group.pool
+
+    @property
     def parent(self):
         return self.group.parent

@@ -576,6 +577,8 @@
         return self.attachment_count

     def destroy(self):
+        # Get reference to pool before unref group
+        pool = self.pool
         for v in self.value.itervalues():
             if hasattr(v, 'destroy'):
                 v.destroy()
@@ -584,4 +587,4 @@
         self.value = None
         self.next = None
         self.destroyed = True
-        POOL[self.model_name].remove(self)
+        pool.remove(self)



--
[email protected] mailing list

Reply via email to