mirror of https://github.com/django/django.git
Refs #25786 -- Added tests/release notes for set_FOO_order() crash with order_with_respect_to referencing OneToOneField pk.
Forwardport of6d9f061b07
from stable/1.8.x The issue was fixed by7bec480fe2
.
This commit is contained in:
parent
8091e8c5c6
commit
e07def14b8
|
@ -42,3 +42,7 @@ Bugfixes
|
||||||
|
|
||||||
* Fixed a duplicate query regression in 1.8 on proxied model deletion
|
* Fixed a duplicate query regression in 1.8 on proxied model deletion
|
||||||
(:ticket:`25685`).
|
(:ticket:`25685`).
|
||||||
|
|
||||||
|
* Fixed ``set_FOO_order()`` crash when the ``ForeignKey`` of a model with
|
||||||
|
``order_with_respect_to`` references a model with a ``OneToOneField``
|
||||||
|
primary key (:ticket:`25786`).
|
||||||
|
|
|
@ -42,3 +42,19 @@ class Post(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
|
# order_with_respect_to points to a model with a OneToOneField primary key.
|
||||||
|
class Entity(models.Model):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Dimension(models.Model):
|
||||||
|
entity = models.OneToOneField('Entity', primary_key=True, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
|
||||||
|
class Component(models.Model):
|
||||||
|
dimension = models.ForeignKey('Dimension', on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
order_with_respect_to = 'dimension'
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.apps.registry import Apps
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from .models import Answer, Post, Question
|
from .models import Answer, Dimension, Entity, Post, Question
|
||||||
|
|
||||||
|
|
||||||
class OrderWithRespectToTests(TestCase):
|
class OrderWithRespectToTests(TestCase):
|
||||||
|
@ -118,3 +118,13 @@ class OrderWithRespectToTests2(TestCase):
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
self.assertEqual(count, 1)
|
self.assertEqual(count, 1)
|
||||||
|
|
||||||
|
|
||||||
|
class TestOrderWithRespectToOneToOnePK(TestCase):
|
||||||
|
def test_set_order(self):
|
||||||
|
e = Entity.objects.create()
|
||||||
|
d = Dimension.objects.create(entity=e)
|
||||||
|
c1 = d.component_set.create()
|
||||||
|
c2 = d.component_set.create()
|
||||||
|
d.set_component_order([c1.id, c2.id])
|
||||||
|
self.assertQuerysetEqual(d.component_set.all(), [c1.id, c2.id], attrgetter('pk'))
|
||||||
|
|
Loading…
Reference in New Issue