﻿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
25027	two relations on the same model with same related_name break the model	karyon	nobody	"consider the following models:
{{{
class UserProfile(models.Model):
    pass

class Course(models.Model):
    participants = models.ManyToManyField(UserProfile, related_name='foo')

class Document(models.Model):
    last_modified_user = models.ForeignKey(UserProfile, related_name='foo')
}}}

and the following query:
{{{
>>> str(Course.objects.first().participants.all().query)
'SELECT ""testapp_userprofile"".""id"" FROM ""testapp_userprofile"" INNER JOIN ""testapp_document"" ON ( ""testapp_userprofile"".""id"" = ""testapp_document"".""last_modified_user_id"" ) WHERE ""testapp_document"".""id"" = 1'
}}}

the join doesn't make any sense to me. it makes both assertions in the following test fail:

{{{
def test_related_name(self):
    user = UserProfile.objects.create()
    course = Course.objects.create()
    course.participants = UserProfile.objects.all()
    self.assertEqual(course.participants.count(), 1)
    self.assertEqual(list(course.participants.all()), [user])
}}}


changing the related name in one of the models to something else fixes this.

i would have expected to get some warning that i'm using the same related name on the same model. especially i expected this to not break when i'm not even using the related name in the test.

this also breaks when using '+' as related name. in this case, i would expect everything to just work."	Bug	new	Uncategorized	1.8	Normal				Unreviewed	0	0	0	0	0	0
