Provide a better error message when polymorphic_ctype_id is Null
refs #51, #140, #304
(cherry picked from commit fb8eed78ad)
This commit is contained in:
@@ -5,6 +5,7 @@ from django.db.models import Case, Count, Q, When
|
||||
from django.test import TestCase
|
||||
from django.utils import six
|
||||
from polymorphic.contrib.guardian import get_polymorphic_base_content_type
|
||||
from polymorphic.models import PolymorphicTypeUndefined
|
||||
from polymorphic.tests import * # all models
|
||||
|
||||
|
||||
@@ -783,6 +784,16 @@ class PolymorphicTests(TestCase):
|
||||
ctype = get_polymorphic_base_content_type(Model2D)
|
||||
self.assertEqual(ctype.name, 'model2a')
|
||||
|
||||
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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user