#24951 closed Bug (fixed)
Error deleting from table with Foreign Key being Primary Key at the same point
Reported by: | Serge Travin | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Release blocker | Keywords: | |
Cc: | hv@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Problem occurs, when trying to issue delete on queryset for a table like this:
class Derivative(models.Model): spot = models.OneToOneField(Spot, primary_key=True) flag = models.BooleanField(default=True) Derivative.objects.filter(spot__name__icontains='name').delete()
Result is:
AssertionError: Can only delete from one table at a time.
However, if we have simple table like this:
class SimpleDerivative(models.Model): spot = models.OneToOneField(Spot) flag = models.BooleanField(default=True)
than there is no problem. Note, there is no primary_key for spot here.
Problem does not exist for Django 1.6 (I didn't check for previous versions)
And persits in 1.7 and 1.8
There is changed code between versions in:
django/db/models/sql/subqueries.py - DeleteQuery.delete_qs
right before the last line self.tables contains two tables, which leads to assertion error.
I provided sample project to reproduce issue - https://github.com/grumbler/django_delete_issue
Simply run the tests with the appropriate Django version installed.
Attachments (1)
Change History (8)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 10 years ago
Attachment: | 24951-test.diff added |
---|
comment:2 by , 9 years ago
Cc: | added |
---|
comment:4 by , 9 years ago
Severity: | Normal → Release blocker |
---|
Not sure, but probably should be a release blocker since it's a regression.
comment:5 by , 9 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Removing the assertion does work, but I guess it probably isn't the correct fix. Any advice from ORM experts?
Bisected to 20bab2cf9d02a5c6477d8aac066a635986e0d3f3. Attaching a regression test for Django's test suite.