mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +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
|
@ -4,6 +4,7 @@ from django import forms
|
|||
from django.contrib.contenttypes.forms import generic_inlineformset_factory
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db import IntegrityError
|
||||
from django.db.models import Q
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
from django.utils import six
|
||||
|
@ -486,6 +487,15 @@ class GenericRelationsTests(TestCase):
|
|||
with self.assertRaisesMessage(FieldError, msg):
|
||||
TaggedItem.objects.get(content_object='')
|
||||
|
||||
def test_unsaved_instance_on_generic_foreign_key(self):
|
||||
"""
|
||||
Assigning an unsaved object to GenericForeignKey should raise an
|
||||
exception on model.save().
|
||||
"""
|
||||
quartz = Mineral(name="Quartz", hardness=7)
|
||||
with self.assertRaises(IntegrityError):
|
||||
TaggedItem.objects.create(tag="shiny", content_object=quartz)
|
||||
|
||||
|
||||
class CustomWidget(forms.TextInput):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue