1
0
mirror of https://github.com/django/django.git synced 2025-10-27 07:36:08 +00:00

Fixed #33312 -- Raised explicit exception when copying deferred model instances.

Previously save() would crash with an attempted forced update message, and both
save(force_insert=True) and bulk_create() would crash with DoesNotExist errors
trying to retrieve rows with an empty primary key (id IS NULL).

Implementing deferred field model instance copying might be doable in certain
cases (e.g. when all the deferred fields are db generated) but that's not
trivial to implement in a backward compatible way.

Thanks Adam Sołtysik for the report and test and Clifford for the review.
This commit is contained in:
Simon Charette
2025-05-06 13:57:20 -04:00
committed by Sarah Boyce
parent 0b2ed4f7c8
commit e03e5c751c
5 changed files with 42 additions and 3 deletions

View File

@@ -180,7 +180,7 @@ class GeneratedFieldTestMixin:
def test_unsaved_error(self):
m = self.base_model(a=1, b=2)
msg = "Cannot read a generated field from an unsaved model."
msg = "Cannot retrieve deferred field 'field' from an unsaved model."
with self.assertRaisesMessage(AttributeError, msg):
m.field