﻿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
32045	Document that GenericRelation.remove()/clear() delete objects.	chgad	Craig Smith	"Hello I'm currently working on some custom logic in the admin interface when i encountered this behavior.

Suppose we have two simple models


{{{
class Photograph(DeepZoom):
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True)
    object_id = models.PositiveIntegerField(default=0)
    profile = GenericForeignKey(""content_type"", ""object_id"")
    img = models.FileField(...)
}}}

and


{{{
class MyProfile(models.Model):
    name = models.CharField(max_length=200, default="""")
    photos = GenericRelation(Photograph, null=True)
}}}

I can confirm that the creation of a ""Photograph"" without a relation to a ""MyProfile"" instance works fine. Also, adding ""Photographs"" to a ""MyProfile"" via


{{{
some_profile_instance.photos.add(some_photograph_instance)
}}}

works just fine.

But as soon as i want to remove a ""Photograph"" from the Relation to a ""MyProfile"" instance the ""Photograph"" instance is not only removed from the relation but also deleted. In the shell it looks like this (pre-created Photographs an MyPofile instance/s):


{{{
In [1]: Photograph.objects.all()
Out[1]: <QuerySet [<Photograph: photograph/file_one.png>, <Photograph: photograph/file_two.png>]>

In [2]: MyProfile.objects.first().photos.all()
Out[2]: <QuerySet [<Photograph: photograph/file_one.png>]>

In [3]: photo_instance = MyProfile.objects.first().photos.first()

In [4]: MyProfile.objects.first().new_photo.remove(photo_instance)

In [5]: MyProfile.objects.first().photos.all()
Out[5]: <QuerySet []> 
# As expected

In [6]: Photograph.objects.all()
Out[6]: <QuerySet [<Photograph: photograph/file_two.png>]>
# ... but the Photograph got entirely deleted
}}}

As far as i understand the docs [https://docs.djangoproject.com/en/3.1/ref/models/relations/#django.db.models.fields.related.RelatedManager.remove]
this is not the expected behavior. If the behavior of ""remove"" is different for GenericRelations i couldn't find any documentation on it.

P.S.: The same issue holds for the ""set"" method.

"	Cleanup/optimization	closed	Documentation	3.1	Normal	fixed		Asjad Ahmed Khan Sumagna Das	Ready for checkin	1	0	0	0	1	0
