Changes between Initial Version and Version 1 of Ticket #36259, comment 14
- Timestamp:
- Oct 20, 2026, 1:22:25 PM (3 weeks ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #36259, comment 14
initial v1 3 3 The original proposed solution was to use `_state.adding` to detect unsaved instances. However, in [https://github.com/django/django/pull/19275 PR #19275], Jacob Walls identified existing workflows that stricter checks would reject: 4 4 5 Querying related objects through a new UUID-backed instance, such as `pizza.toppings.all()`.6 Saving interdependent objects within a transaction where foreign-key constraints are checked after both objects have been saved.5 - Querying related objects through a new UUID-backed instance, such as `pizza.toppings.all()`. 6 - Saving interdependent objects within a transaction where foreign-key constraints are checked after both objects have been saved. 7 7 8 8 I’ve investigated the four cases described in this ticket. On the tested checkout, with `SQLite`: 9 9 10 Saving with a missing referenced row raises `IntegrityError` when the constraint is checked.11 `contains()` returns `False` for an assigned PK with no matching row.12 Related `filter()` and `exclude()` queries execute without an unsaved-object error.13 Reading an unloaded generated field with an assigned PK but no matching row raises `DoesNotExist`.10 - Saving with a missing referenced row raises `IntegrityError` when the constraint is checked. 11 - `contains()` returns `False` for an assigned PK with no matching row. 12 - Related `filter()` and `exclude()` queries execute without an unsaved-object error. 13 - Reading an unloaded generated field with an assigned PK but no matching row raises `DoesNotExist`. 14 14 15 15 I have an uncommitted prototype addressing only the generated-field case. It allows the normal lookup, preserving successful retrieval when the PK identifies an existing row. If that lookup raises the model’s `DoesNotExist` and the instance is marked as adding, it raises the existing unsaved-field `AttributeError` instead. It does not change saves, membership checks, or related filters.