1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

[1.8.x] Fixed #25160 -- Moved unsaved model instance data loss check to Model.save()

This mostly reverts 5643a3b51b and
81e1a35c36.

Thanks Carl Meyer for review.

Backport of 5980b05c1f from master
This commit is contained in:
Tim Graham
2015-07-24 07:51:40 -04:00
parent 90c7078f48
commit e4b813c0e7
15 changed files with 107 additions and 195 deletions

View File

@@ -2,8 +2,8 @@ import json
import uuid
from django.core import exceptions, serializers
from django.db import models
from django.test import TestCase
from django.db import IntegrityError, models
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
from .models import (
NullableUUIDModel, PrimaryKeyUUIDModel, RelatedToUUIDModel, UUIDGrandchild,
@@ -151,3 +151,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)