Opened 5 years ago
Closed 5 years ago
#31433 closed Bug (invalid)
Model.objects.create() doesn't utilize caching for prefetches defined on the ObjectManager.
Reported by: | Nathan Yan | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.0 |
Severity: | Normal | Keywords: | prefetch cache |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In this example:
class Foo(models.Model): objects = FooManager() class FooManager(models.Manager): def get_queryset(self): return (...).prefetch_related("bars") fooA = Foo.objects.get(...) fooA.bars # already prefetched + cached for later fooB = Foo.objects.create() fooB.bars # not prefetched fooB.bars # queries again because not included in prefetch cache
I would expect fooA and fooB's caches to behave similarly since they're sourced from the same ObjectManager. If it's not a bug, is there a way to specify the same prefetch_related
caching functionality for created objects?
Change History (1)
comment:1 by , 5 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Summary: | Model.objects.create() doesn't utilize caching for prefetches defined on the ObjectManager → Model.objects.create() doesn't utilize caching for prefetches defined on the ObjectManager. |
Note:
See TracTickets
for help on using tickets.
get_queryset()
is not called for new objects created withQuerySet.create()
. It's not a bug in Django it's a false assumption that you made in your implementation. Please use one of support channels.Closing per TicketClosingReasons/UseSupportChannels.