Check for instance in cache to have the appropriate foreignkey if we're called from a related manager. Stops us from retrieving any object by ID, whether it was related to us or not.

This commit is contained in:
Tehom 2017-05-07 02:12:58 -04:00
parent 4f76d255fa
commit 6ea13dbc96

View file

@ -25,6 +25,12 @@ class SharedMemoryManager(Manager):
key = key[:-len('__exact')]
if key in ('pk', self.model._meta.pk.attname):
inst = self.model.get_cached_instance(kwargs[items[0]])
try:
# we got the item from cache, but if this is a fk, check it's ours
if getattr(inst, str(self.field).split(".")[-1]) != self.instance:
inst = None
except Exception:
pass
if inst is None:
inst = super(SharedMemoryManager, self).get(*args, **kwargs)
return inst