Provide a better error message when polymorphic_ctype_id is Null

refs #51, #140, #304
This commit is contained in:
Diederik van der Boor
2017-08-01 11:38:36 +02:00
parent b772c06358
commit fb8eed78ad
2 changed files with 23 additions and 0 deletions
+12
View File
@@ -4,6 +4,8 @@ import django
from django.db.models import Case, Count, Q, When
from django.test import TestCase
from django.utils import six
from polymorphic.models import PolymorphicTypeUndefined
from polymorphic.tests import * # all models
@@ -765,6 +767,16 @@ class PolymorphicTests(TestCase):
result = Model2B.objects.annotate(val=Concat('field1', 'field2'))
self.assertEqual(list(result), [])
def test_null_polymorphic_id(self):
"""Test that a proper error message is displayed when the database lacks the ``polymorphic_ctype_id``"""
Model2A.objects.create(field1='A1')
Model2B.objects.create(field1='A1', field2='B2')
Model2B.objects.create(field1='A1', field2='B2')
Model2A.objects.all().update(polymorphic_ctype_id=None)
with self.assertRaises(PolymorphicTypeUndefined):
list(Model2A.objects.all())
def qrepr(data):
"""