﻿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
2573	Relating two models to the same model using generic relations with the same parameters causes conflicts	Chris Long	Adrian Holovaty	"Using the following models:
{{{
#!python
class Group(models.Model):
...
    row_level_permissions_owned = models.GenericRelation(RowLevelPermission, object_id_field=""owner_id"", content_type_field=""owner_ct"", related_name=""owner"")
...

class User(models.Model):
...
    row_level_permissions_owned = models.GenericRelation(RowLevelPermission, object_id_field=""owner_id"", content_type_field=""owner_ct"", related_name=""owner"")
...

class RowLevelPermission(models.Model):
class RowLevelPermission(models.Model):
...
    owner_id = models.PositiveIntegerField(""'Owner' ID"")
    owner_ct = models.ForeignKey(ContentType, verbose_name=""'Owner' content type"", related_name=""owner_ct"")
...    
    model = models.GenericForeignKey(fk_field='model_id', ct_field='model_ct')
    owner = models.GenericForeignKey(fk_field='owner_id', ct_field='owner_ct')
}}}

Causes the following errors:
{{{
auth.user: Accessor for m2m field 'row_level_permissions_owned' clashes with related m2m field 'RowLevelPermission.owner'. Add a related_name argument to the definition for 'row_level_permissions_owned'.
auth.user: Reverse query name for m2m field 'row_level_permissions_owned' clashes with related m2m field 'RowLevelPermission.owner'. Add a related_name argument to the definition for 'row_level_permissions_owned'.
auth.group: Accessor for m2m field 'row_level_permissions_owned' clashes with related m2m field 'RowLevelPermission.owner'. Add a related_name argument to the definition for 'row_level_permissions_owned'.
auth.group: Reverse query name for m2m field 'row_level_permissions_owned' clashes with related m2m field 'RowLevelPermission.owner'. Add a related_name argument to the definition for 'row_level_permissions_owned'.
}}}

By changing the two related_names to be different from another will stop this error. As long as the two related_names are the same (no matter what they are) the error happens. 

From what I've been able to determine this happens because Django believes this to be a M2M relationship that contributes an attribute to the related class (which it does not) and having two attributes of the same name for two different relationships on the same object causes it to believe there is an error."	defect	closed	Database layer (models, ORM)	dev	normal	invalid	generic relations, database		Unreviewed	0	0	0	0	0	0
