Refs #33579 -- Added extra tests for NotUpdated exception.

When `NotUpdated` was added in ab148c02ce,
these additional tests that have equivalents for the `DoesNotExist` and
`MultipleObjectsReturned` exceptions were missed.
This commit is contained in:
Nick Pope
2026-02-03 10:14:31 +00:00
committed by Jacob Walls
parent 13299a6203
commit 6f8b2d1c6d
3 changed files with 15 additions and 3 deletions

View File

@@ -449,6 +449,12 @@ class ModelInheritanceDataTests(TestCase):
with self.assertRaises(Place.MultipleObjectsReturned):
Restaurant.objects.get()
def test_inherited_not_updated_exception(self):
# NotUpdated is also inherited.
obj = Restaurant(id=999)
with self.assertRaises(Place.NotUpdated):
obj.save(update_fields={"name"})
def test_related_objects_for_inherited_models(self):
# Related objects work just as they normally do.
s1 = Supplier.objects.create(name="Joe's Chickens", address="123 Sesame St")

View File

@@ -2,7 +2,7 @@ from django.contrib import admin
from django.contrib.auth.models import User as AuthUser
from django.contrib.contenttypes.models import ContentType
from django.core import checks, management
from django.db import DEFAULT_DB_ALIAS, models
from django.db import DEFAULT_DB_ALIAS, models, transaction
from django.db.models import signals
from django.test import TestCase, override_settings
from django.test.utils import isolate_apps
@@ -104,8 +104,8 @@ class ProxyModelTests(TestCase):
def test_proxy_included_in_ancestors(self):
"""
Proxy models are included in the ancestors for a model's DoesNotExist
and MultipleObjectsReturned
Proxy models are included in the ancestors for a model's DoesNotExist,
MultipleObjectsReturned, and NotUpdated
"""
Person.objects.create(name="Foo McBar")
MyPerson.objects.create(name="Bazza del Frob")
@@ -118,6 +118,8 @@ class ProxyModelTests(TestCase):
MyPersonProxy.objects.get(id__lt=max_id + 1)
with self.assertRaises(Person.DoesNotExist):
StatusPerson.objects.get(name="Zathras")
with self.assertRaises(Person.NotUpdated), transaction.atomic():
StatusPerson(id=999).save(update_fields={"name"})
StatusPerson.objects.create(name="Bazza Jr.")
StatusPerson.objects.create(name="Foo Jr.")

View File

@@ -70,6 +70,10 @@ class PickleabilityTestCase(TestCase):
klass = Event.MultipleObjectsReturned
self.assertIs(pickle.loads(pickle.dumps(klass)), klass)
def test_not_updated_class(self):
klass = Event.NotUpdated
self.assertIs(pickle.loads(pickle.dumps(klass)), klass)
def test_forward_relatedobjectdoesnotexist_class(self):
# ForwardManyToOneDescriptor
klass = Event.group.RelatedObjectDoesNotExist