mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #25160 -- Moved unsaved model instance data loss check to Model.save()
This mostly reverts5643a3b51b
and81e1a35c36
. Thanks Carl Meyer for review.
This commit is contained in:
parent
12f91f6ebd
commit
5980b05c1f
15 changed files with 106 additions and 198 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue