Changes between Initial Version and Version 1 of Ticket #36259, comment 14


Ignore:
Timestamp:
Oct 20, 2026, 1:22:25 PM (3 weeks ago)
Author:
Alin Morosanu

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36259, comment 14

    initial v1  
    33The 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:
    44
    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.
    77
    88I’ve investigated the four cases described in this ticket. On the tested checkout, with `SQLite`:
    99
    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`.
    1414
    1515I 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.
Back to Top