From 5980b05c1fad69eef907e0076aa2dc837edab529 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 24 Jul 2015 07:51:40 -0400 Subject: Fixed #25160 -- Moved unsaved model instance data loss check to Model.save() This mostly reverts 5643a3b51be338196d0b292d5626ad43648448d3 and 81e1a35c364e5353d2bf99368ad30a4184fbb653. Thanks Carl Meyer for review. --- tests/model_fields/test_uuid.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests/model_fields') diff --git a/tests/model_fields/test_uuid.py b/tests/model_fields/test_uuid.py index bef1d54a74..343140c248 100644 --- a/tests/model_fields/test_uuid.py +++ b/tests/model_fields/test_uuid.py @@ -2,8 +2,10 @@ import json import uuid from django.core import exceptions, serializers -from django.db import models -from django.test import SimpleTestCase, TestCase +from django.db import IntegrityError, models +from django.test import ( + SimpleTestCase, TestCase, TransactionTestCase, skipUnlessDBFeature, +) from .models import ( NullableUUIDModel, PrimaryKeyUUIDModel, RelatedToUUIDModel, UUIDGrandchild, @@ -158,3 +160,14 @@ class TestAsPrimaryKey(TestCase): def test_two_level_foreign_keys(self): # exercises ForeignKey.get_db_prep_value() UUIDGrandchild().save() + + +class TestAsPrimaryKeyTransactionTests(TransactionTestCase): + # Need a TransactionTestCase to avoid deferring FK constraint checking. + available_apps = ['model_fields'] + + @skipUnlessDBFeature('supports_foreign_keys') + def test_unsaved_fk(self): + u1 = PrimaryKeyUUIDModel() + with self.assertRaises(IntegrityError): + RelatedToUUIDModel.objects.create(uuid_fk=u1) -- cgit v1.3