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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24951>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_better_patch: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Bisected to 20bab2cf9d02a5c6477d8aac066a635986e0d3f3. Attaching a
regression test for Django's test suite.
--
Ticket URL: <https://code.djangoproject.com/ticket/24951#comment:1>
* Attachment "24951-test.diff" added.
* cc: hv@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24951#comment:2>
Comment (by guettli):
Is there are known work around until this is fixed?
--
Ticket URL: <https://code.djangoproject.com/ticket/24951#comment:3>
* severity: Normal => Release blocker
Comment:
Not sure, but probably should be a release blocker since it's a
regression.
--
Ticket URL: <https://code.djangoproject.com/ticket/24951#comment:4>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/5109 Removing the assertion] does
work, but I guess it probably isn't the correct fix. Any advice from ORM
experts?
--
Ticket URL: <https://code.djangoproject.com/ticket/24951#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"333cbdcd2de4546e33ad50ebd8b67e1a1e87aeec" 333cbdc]:
{{{
#!CommitTicketReference repository=""
revision="333cbdcd2de4546e33ad50ebd8b67e1a1e87aeec"
Fixed #24951 -- Fixed AssertionError in delete queries involving a
foreign/primary key.
Thanks Anssi Kääriäinen for help.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24951#comment:6>
Comment (by Tim Graham <timograham@…>):
In [changeset:"ffe755e990fa7e680960c7a413d387a79f194204" ffe755e9]:
{{{
#!CommitTicketReference repository=""
revision="ffe755e990fa7e680960c7a413d387a79f194204"
[1.8.x] Fixed #24951 -- Fixed AssertionError in delete queries involving a
foreign/primary key.
Thanks Anssi Kääriäinen for help.
Backport of 333cbdcd2de4546e33ad50ebd8b67e1a1e87aeec from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24951#comment:7>