Commit 1f4f2ffb authored by gushitong's avatar gushitong

bugfix: get same obj for different obj_id

parent c5047cc2
__version__ = '0.0.5'
__version__ = '0.0.6'
__author__ = 'gushitong@gmei.com'
......@@ -25,13 +25,17 @@ class MagicDescriptor(object):
if instance is None:
return self
related_obj_pk = getattr(instance, "%s_id" % self.field.attname)
if getattr(instance, self.lazy_name, False):
return getattr(instance, "%s_id" % self.field.attname)
return related_obj_pk
try:
lazy_obj = getattr(instance, self.cache_name)
logger.debug("Magic Hit ObjCache: %s:%s" % (self.field.attname, lazy_obj['id']))
except AttributeError:
# update field pk_list, or you always get the same.
self.field.accessor.pk_list = [related_obj_pk]
lazy_obj = self.field.accessor.get_object()
setattr(instance, self.cache_name, lazy_obj)
return lazy_obj
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment