#26162: Data loss when ManyToManyField refers to the wrong table
----------------------------------------------+--------------------
Reporter: Ian-Foote | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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
--
Ticket URL: <https://code.djangoproject.com/ticket/26162>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.3c8fb7e198c0105a87cfe2349ea7bd5b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.