diff options
| author | Tim Graham <timograham@gmail.com> | 2015-11-20 11:31:39 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-23 12:08:29 -0500 |
| commit | 8edf8db52f626e6bf384a729063f91caa6592f92 (patch) | |
| tree | 9223f22fea08b14a0ab199fb046bb4252b666a34 | |
| parent | 8957dfe4ad76b74744abdbde605d06fb565a55e3 (diff) | |
[1.9.x] Refs #25786 -- Added tests/release notes for set_FOO_order() crash with order_with_respect_to referencing OneToOneField pk.
Forwardport of 6d9f061b07ce7aa1a9da6799b3104971ee73998b from stable/1.8.x
The issue was fixed by 7bec480fe2ace94c8e7f0c88485442bfa74436b4.
| -rw-r--r-- | docs/releases/1.8.7.txt | 4 | ||||
| -rw-r--r-- | tests/order_with_respect_to/models.py | 16 | ||||
| -rw-r--r-- | tests/order_with_respect_to/tests.py | 12 |
3 files changed, 31 insertions, 1 deletions
diff --git a/docs/releases/1.8.7.txt b/docs/releases/1.8.7.txt index df0ff41159..b11ea9781a 100644 --- a/docs/releases/1.8.7.txt +++ b/docs/releases/1.8.7.txt @@ -42,3 +42,7 @@ Bugfixes * Fixed a duplicate query regression in 1.8 on proxied model deletion (: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`). diff --git a/tests/order_with_respect_to/models.py b/tests/order_with_respect_to/models.py index 5f531a32a5..742818337c 100644 --- a/tests/order_with_respect_to/models.py +++ b/tests/order_with_respect_to/models.py @@ -42,3 +42,19 @@ class Post(models.Model): def __str__(self): 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' diff --git a/tests/order_with_respect_to/tests.py b/tests/order_with_respect_to/tests.py index 8f01660180..6157f51d4e 100644 --- a/tests/order_with_respect_to/tests.py +++ b/tests/order_with_respect_to/tests.py @@ -6,7 +6,7 @@ from django.apps.registry import Apps from django.db import models from django.test import TestCase -from .models import Answer, Post, Question +from .models import Answer, Dimension, Entity, Post, Question class OrderWithRespectToTests(TestCase): @@ -118,3 +118,13 @@ class OrderWithRespectToTests2(TestCase): 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')) |
