1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #33004 -- Made saving objects with unsaved GenericForeignKey raise ValueError.

This aligns to the behaviour of OneToOneField and ForeignKey fields.

Thanks Jonny Park for the initial patch.
This commit is contained in:
sarahboyce
2022-04-19 13:21:23 +02:00
committed by Mariusz Felisiak
parent 1ed8ca43f6
commit cd4da34fc1
4 changed files with 38 additions and 26 deletions

View File

@@ -1,4 +1,3 @@
from django.db import IntegrityError
from django.db.models import ProtectedError, Q, Sum
from django.forms.models import modelform_factory
from django.test import TestCase, skipIfDBFeature
@@ -15,7 +14,6 @@ from .models import (
Contact,
Content,
D,
Developer,
Guild,
HasLinkThing,
Link,
@@ -140,14 +138,6 @@ class GenericRelationTests(TestCase):
self.assertEqual(count_places(p1), 1)
self.assertEqual(count_places(p2), 1)
def test_target_model_is_unsaved(self):
"""Test related to #13085"""
# Fails with another, ORM-level error
dev1 = Developer(name="Joe")
note = Note(note="Deserves promotion", content_object=dev1)
with self.assertRaises(IntegrityError):
note.save()
def test_target_model_len_zero(self):
"""
Saving a model with a GenericForeignKey to a model instance whose