Fix caching leftover in attribute cache that lead to a traceback on the first re-login. Resolves #1041.
This commit is contained in:
parent
ce0bfe8a0d
commit
dc32300092
1 changed files with 13 additions and 6 deletions
|
|
@ -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,6 +278,7 @@ 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:
|
||||||
|
if attr.pk:
|
||||||
cachekey = "%s-%s" % (attr.db_key, category)
|
cachekey = "%s-%s" % (attr.db_key, category)
|
||||||
self._cache[cachekey] = attr
|
self._cache[cachekey] = attr
|
||||||
# mark category cache as up-to-date
|
# mark category cache as up-to-date
|
||||||
|
|
@ -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,7 +574,12 @@ 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)):
|
||||||
|
try:
|
||||||
attr_obj.delete()
|
attr_obj.delete()
|
||||||
|
except AssertionError:
|
||||||
|
# this happens if the attr was already deleted
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
self._delcache(key, category)
|
self._delcache(key, category)
|
||||||
if not attr_objs and raise_exception:
|
if not attr_objs and raise_exception:
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue