diff options
author | ZachLiuGIS <zachliugis@gmail.com> | 2016-02-10 20:46:57 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-02-11 10:07:39 -0500 |
commit | 04e13c89138d48c20e774a2b6bf06796f73ac0fe (patch) | |
tree | 0023c60c24ace9e5dc2a176ffbf0f8c0c10f9c74 /tests/many_to_one | |
parent | 353aecbf8c1a8cc6f3985149e2895d49e53dfc1c (diff) | |
download | django-04e13c89138d48c20e774a2b6bf06796f73ac0fe.tar.gz |
Fixed #26179 -- Removed null assignment check for non-nullable foreign key fields.
Diffstat (limited to 'tests/many_to_one')
-rw-r--r-- | tests/many_to_one/tests.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index e8210955ce..c5a0e3f8f3 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -3,6 +3,7 @@ from copy import deepcopy from django.core.exceptions import FieldError, MultipleObjectsReturned from django.db import models, transaction +from django.db.utils import IntegrityError from django.test import TestCase from django.utils import six from django.utils.deprecation import RemovedInDjango20Warning @@ -486,19 +487,19 @@ class ManyToOneTests(TestCase): p = Parent.objects.get(name="Parent") self.assertIsNone(p.bestchild) - # Assigning None fails: Child.parent is null=False. - with self.assertRaises(ValueError): - setattr(c, "parent", None) + # Assigning None will not fail: Child.parent is null=False. + setattr(c, "parent", None) # You also can't assign an object of the wrong type here with self.assertRaises(ValueError): setattr(c, "parent", First(id=1, second=1)) - # Nor can you explicitly assign None to Child.parent during object - # creation (regression for #9649). - with self.assertRaises(ValueError): - Child(name='xyzzy', parent=None) - with self.assertRaises(ValueError): + # You can assign None to Child.parent during object creation. + Child(name='xyzzy', parent=None) + + # But when trying to save a Child with parent=None, the database will + # raise IntegrityError. + with self.assertRaises(IntegrityError), transaction.atomic(): Child.objects.create(name='xyzzy', parent=None) # Creation using keyword argument should cache the related object. |