﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34633	Add prefetch_related() cache invalidation for create() in reverse many-to-one managers.	Rob Percival	Aman Pandey	"[https://docs.djangoproject.com/en/4.0/ref/models/querysets/#prefetch-related The documentation] says:
> if you call the database-altering methods add(), remove(), clear() or set(), on related managers, any prefetched cache for the relation will be cleared.

This is accurate. However, there are other database-altering methods, such as create(), for which the cache ought to be cleared but isn't. This results in this confusing state of affairs:

{{{
x = MyModel.objects.prefetch_related(""related_objects"").get()
assert len(x.related_objects.all()) == 0
x.related_objects.create()
assert len(x.related_objects.all()) == 1  # Assertion fails because the prefetch cache isn't cleared by create()
}}}

Using add() rather than create() would cause the above code to work as expected. If there's a good reason for create() not clearing the cache, could that be documented please? Otherwise, could it clear the cache? From a search of Stack Overflow, this is definitely a source of confusion for some."	Bug	closed	Database layer (models, ORM)	4.2	Normal	fixed			Ready for checkin	1	0	0	0	1	0
