mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #25160 -- Moved unsaved model instance data loss check to Model.save()
This mostly reverts5643a3b51band81e1a35c36. Thanks Carl Meyer for review.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user