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:
parent
4f76d255fa
commit
6ea13dbc96
1 changed files with 6 additions and 0 deletions
|
|
@ -25,6 +25,12 @@ class SharedMemoryManager(Manager):
|
||||||
key = key[:-len('__exact')]
|
key = key[:-len('__exact')]
|
||||||
if key in ('pk', self.model._meta.pk.attname):
|
if key in ('pk', self.model._meta.pk.attname):
|
||||||
inst = self.model.get_cached_instance(kwargs[items[0]])
|
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:
|
if inst is None:
|
||||||
inst = super(SharedMemoryManager, self).get(*args, **kwargs)
|
inst = super(SharedMemoryManager, self).get(*args, **kwargs)
|
||||||
return inst
|
return inst
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue