Use WeakValueDictionary instead of WeakSet in DBModelProxy

Current implementation of DBModelProxy doesnt allow to use
origin hash function of Model class.

In order to avoid this problem we will store references to
Model instances in WeakValueDictionary instead of WeakSet.

Change-Id: If92af140c9aaad3a46b24872dae16969b1090df8
Closes-Bug: 1560369
This commit is contained in:
Dmitry Shulyak 2016-03-22 10:44:49 +02:00
parent 29d3306491
commit 8f1ca9708a
2 changed files with 3 additions and 5 deletions

View File

@ -91,7 +91,7 @@ class SingleClassCache(object):
self.obj_cache = LFUCache(origin_class, 200)
self.db_ch_state = {'index': set()}
self.lazy_save = set()
self.refs = defaultdict(weakref.WeakSet)
self.refs = defaultdict(weakref.WeakValueDictionary)
self.origin_class = origin_class

View File

@ -21,15 +21,13 @@ class DBLayerProxy(wrapt.ObjectProxy):
def __init__(self, wrapped):
super(DBLayerProxy, self).__init__(wrapped)
refs = wrapped._c.refs
refs[wrapped.key].add(self)
refs[wrapped.key][id(wrapped)] = wrapped
def next(self, *args, **kwargs):
return self.__wrapped__.next(*args, **kwargs)
def __hash__(self):
# id is there by intention
# we override __has__ in model
return hash(id(self.__wrapped__))
return hash(self.__wrapped__)
def __eq__(self, other):
if not isinstance(other, DBLayerProxy):