1
0
mirror of https://github.com/django/django.git synced 2025-06-07 20:49:11 +00:00

Refs #33579: Changed exception raised when no rows are affected to a more specialized one

This commit is contained in:
Enrique Soria 2024-06-08 14:45:26 +02:00
parent adae619426
commit 2ab106a02b
2 changed files with 7 additions and 3 deletions

View File

@ -20,7 +20,6 @@ from django.core.exceptions import (
) )
from django.db import ( from django.db import (
DJANGO_VERSION_PICKLE_KEY, DJANGO_VERSION_PICKLE_KEY,
DatabaseError,
connection, connection,
connections, connections,
router, router,
@ -48,6 +47,7 @@ from django.db.models.signals import (
pre_save, pre_save,
) )
from django.db.models.utils import AltersData, make_model_tuple from django.db.models.utils import AltersData, make_model_tuple
from django.db.utils import NoRowsAffected
from django.utils.deprecation import RemovedInDjango60Warning from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.encoding import force_str from django.utils.encoding import force_str
from django.utils.hashable import make_hashable from django.utils.hashable import make_hashable
@ -1112,9 +1112,9 @@ class Model(AltersData, metaclass=ModelBase):
base_qs, using, pk_val, values, update_fields, forced_update base_qs, using, pk_val, values, update_fields, forced_update
) )
if force_update and not updated: if force_update and not updated:
raise DatabaseError("Forced update did not affect any rows.") raise NoRowsAffected("Forced update did not affect any rows.")
if update_fields and not updated: if update_fields and not updated:
raise DatabaseError("Save with update_fields did not affect any rows.") raise NoRowsAffected("Save with update_fields did not affect any rows.")
if not updated: if not updated:
if meta.order_with_respect_to: if meta.order_with_respect_to:
# If this is a model with an order_with_respect_to # If this is a model with an order_with_respect_to

View File

@ -26,6 +26,10 @@ class DatabaseError(Error):
pass pass
class NoRowsAffected(DatabaseError):
pass
class DataError(DatabaseError): class DataError(DatabaseError):
pass pass