﻿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
25344	Document that prefetch_related() cache doesn't change unless it's refetched from the database	Stefan Schindler	nobody	"When calling `add()` on a related field (ForeignKey) that has been prefetched, albeit the added object is processed at database level, it's not added to the prefetched collection. Following calls to `field.all()` therefore do not contain the added object.

Example:


{{{#!python
from example.models import *

Article.objects.all().delete()
Author.objects.all().delete()

Author().save()

author = Author.objects.all().prefetch_related(""articles"").first()
author.articles.add(Article())

print(list(author.articles.all()))
print(list(Article.objects.all()))
}}}

Prints:

{{{
[]
[<Article: Article object>]
}}}

I could not find an info in the documentation about that behavior, and it can be very hard to spot in bigger code bases. This should not fail silently in my opinion, and disallowing adding to prefetched related fields might even be an option.

Here's the link to a complete minimal project setup; the code from above can just be pasted in a manage.py shell session: https://github.com/TankOs/django_prefetch_add"	Cleanup/optimization	closed	Documentation	1.8	Normal	invalid	prefetch_related		Accepted	0	0	0	0	0	0
