Fix caching leftover in attribute cache that lead to a traceback on the first re-login. Resolves #1041.

This commit is contained in:
Griatch 2016-09-08 20:46:11 +02:00
parent ce0bfe8a0d
commit dc32300092

View file

@ -262,7 +262,7 @@ class AttributeHandler(object):
if conn: if conn:
attr = conn[0].attribute attr = conn[0].attribute
self._cache[cachekey] = attr self._cache[cachekey] = attr
return [attr] return [attr] if attr.pk else []
else: else:
# only category given (even if it's None) - we can't # only category given (even if it's None) - we can't
# assume the cache to be complete unless we have queried # assume the cache to be complete unless we have queried
@ -278,8 +278,9 @@ class AttributeHandler(object):
attrs = [conn.attribute for conn in getattr(self.obj, attrs = [conn.attribute for conn in getattr(self.obj,
self._m2m_fieldname).through.objects.filter(**query)] self._m2m_fieldname).through.objects.filter(**query)]
for attr in attrs: for attr in attrs:
cachekey = "%s-%s" % (attr.db_key, category) if attr.pk:
self._cache[cachekey] = attr cachekey = "%s-%s" % (attr.db_key, category)
self._cache[cachekey] = attr
# mark category cache as up-to-date # mark category cache as up-to-date
self._catcache[catkey] = True self._catcache[catkey] = True
return attrs return attrs
@ -318,7 +319,8 @@ class AttributeHandler(object):
cachekey = "%s-%s" % (key, category) cachekey = "%s-%s" % (key, category)
self._cache.pop(cachekey, None) self._cache.pop(cachekey, None)
else: else:
[self._cache.pop(key, None) for key in self._cache if key.endswith(catkey)] self._cache = {key: attrobj for key, attrobj in
self._cache.items() if not key.endswith(catkey)}
# mark that the category cache is no longer up-to-date # mark that the category cache is no longer up-to-date
self._catcache.pop(catkey, None) self._catcache.pop(catkey, None)
self._cache_complete = False self._cache_complete = False
@ -572,8 +574,13 @@ class AttributeHandler(object):
for attr_obj in attr_objs: for attr_obj in attr_objs:
if not (accessing_obj and not attr_obj.access(accessing_obj, if not (accessing_obj and not attr_obj.access(accessing_obj,
self._attredit, default=default_access)): self._attredit, default=default_access)):
attr_obj.delete() try:
self._delcache(key, category) attr_obj.delete()
except AssertionError:
# this happens if the attr was already deleted
pass
finally:
self._delcache(key, category)
if not attr_objs and raise_exception: if not attr_objs and raise_exception:
raise AttributeError raise AttributeError