﻿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
26162	Data loss when ManyToManyField refers to the wrong table	Ian Foote	Simon Charette	"If I have two identically named models in two different apps, but these models each have a {{{ManyToManyField}}} to the same model, then one of these {{{ManyToManyField}}}s will use the other's database table.

App 1:

{{{
class Bar(models.Model):
    name = models.CharField(max_length=255)

class Foo(models.Model):
    name = models.CharField(max_length=255)
    bars = models.ManyToManyField(Bar, related_name='+')
}}}

App 2:

{{{
from app1.models import Bar

class Foo(models.Model):
   name = models.CharField(max_length=255)
   bars = models.ManyToManyField(Bar, related_name='+')
}}}

Tests:

{{{
from app1.models import Bar, Foo

def test_add_bar_to_foo():
    bar = Bar.objects.create()
    foo = Foo.objects.create()

    foo.bars.add(bar)

    assert bar in foo.bars.all()
}}}

I expect the test to pass, but instead it fails.

A working example of this code can be found at: https://github.com/Ian-Foote/django-bug-sandbox/pull/2"	Bug	closed	Database layer (models, ORM)	1.8	Release blocker	fixed		Simon Charette	Ready for checkin	1	0	0	0	0	0
