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 reverts5643a3b51band81e1a35c36. Thanks Carl Meyer for review. Backport of5980b05c1ffrom master
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user