mirror of https://github.com/django/django.git
[1.8.x] Fixed #24951 -- Fixed AssertionError in delete queries involving a foreign/primary key.
Thanks Anssi Kääriäinen for help.
Backport of 333cbdcd2d
from master
This commit is contained in:
parent
3fa5229600
commit
ffe755e990
|
@ -986,7 +986,7 @@ class SQLDeleteCompiler(SQLCompiler):
|
|||
Creates the SQL for this query. Returns the SQL string and list of
|
||||
parameters.
|
||||
"""
|
||||
assert len(self.query.tables) == 1, \
|
||||
assert len([t for t in self.query.tables if self.query.alias_refcount[t] > 0]) == 1, \
|
||||
"Can only delete from one table at a time."
|
||||
qn = self.quote_name_unless_alias
|
||||
result = ['DELETE FROM %s' % qn(self.query.tables[0])]
|
||||
|
|
|
@ -9,4 +9,5 @@ Django 1.8.5 fixes several bugs in 1.8.4.
|
|||
Bugfixes
|
||||
========
|
||||
|
||||
* ...
|
||||
* Fixed ``AssertionError`` in some delete queries with a model containing a
|
||||
field that is both a foreign and primary key (:ticket:`24951`).
|
||||
|
|
|
@ -83,7 +83,7 @@ class MultiModel(models.Model):
|
|||
|
||||
|
||||
class Target(models.Model):
|
||||
pass
|
||||
name = models.CharField(max_length=50)
|
||||
|
||||
|
||||
class Pointer(models.Model):
|
||||
|
|
|
@ -5,7 +5,8 @@ from django.test import TestCase
|
|||
|
||||
from .models import (
|
||||
Bar, Director, Favorites, HiddenPointer, ManualPrimaryKey, MultiModel,
|
||||
Place, RelatedModel, Restaurant, School, Target, UndergroundBar, Waiter,
|
||||
Place, Pointer, RelatedModel, Restaurant, School, Target, UndergroundBar,
|
||||
Waiter,
|
||||
)
|
||||
|
||||
|
||||
|
@ -256,6 +257,11 @@ class OneToOneTests(TestCase):
|
|||
[]
|
||||
)
|
||||
|
||||
def test_o2o_primary_key_delete(self):
|
||||
t = Target.objects.create(name='name')
|
||||
Pointer.objects.create(other=t)
|
||||
Pointer.objects.filter(other__name='name').delete()
|
||||
|
||||
def test_reverse_object_does_not_exist_cache(self):
|
||||
"""
|
||||
Regression for #13839 and #17439.
|
||||
|
|
Loading…
Reference in New Issue