Changes between Initial Version and Version 1 of Ticket #33579
- Timestamp:
- Mar 15, 2022, 5:06:39 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #33579 – Description
initial v1 1 1 When `Model.save(update_fields)` is used to update an instance of a previously fetched model and the resulting `UPDATE` doesn't affect any row a `DatabaseError` [https://github.com/django/django/blob/3b3f38b3b09b0f2373e51406ecb8c9c45d36aebc/django/db/models/base.py#L1000 is raised]. 2 2 3 Since the resulting exception cannot be differentiated by its `type` from any other exception raisedduring `save` (e.g. a failed `UPDATE` also results in a `DatabaseError`) the only pattern to gracefully handle this rare edge case to catch all `DatabaseError` and compare its `.args[0]` (or `str` representation) to a string that doesn't offer any stability guarantees.3 Since the resulting exception cannot be differentiated by its `type` from any other dababase errors occuring during `save` (e.g. a failed `UPDATE` also results in a `DatabaseError`) the only pattern to gracefully handle this rare edge case to catch all `DatabaseError` and compare its `.args[0]` (or `str` representation) to a string that doesn't offer any stability guarantees. 4 4 5 In order to make it easier for advanced users that rely on the `update_fields` feature to handle this case differently from others where a `DatabaseError` is raised I propose that that we introduce da new `DatabaseError` subclass that would be raised instead when an unexpected empty update occurs.5 In order to make it easier for advanced users that rely on the `update_fields` feature to handle this case differently from others where a `DatabaseError` is raised I propose that that we introduce a new `DatabaseError` subclass that would be raised instead when an unexpected empty update occurs. 6 6 7 7 I believe [https://github.com/django/django/blob/3b3f38b3b09b0f2373e51406ecb8c9c45d36aebc/django/db/models/base.py#L997-L1000 both instances] should be switched to this pattern (`force_update` and `update_fields`).