Changes between Initial Version and Version 1 of Ticket #37309


Ignore:
Timestamp:
Aug 31, 2026, 11:00:05 AM (109 minutes ago)
Author:
Denny Biasiolli
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37309 – Description

    initial v1  
    1 `Model.__eq__` still uses `pk is None` to decide whether an instance is unsaved. That is wrong for composite primary keys (`pk` is a tuple) and for `db_default` PKs (`DatabaseDefault` is not `None`).
     1{{{Model.__eq__}}} still uses {{{pk is None}}} to decide whether an instance is unsaved. That is wrong for composite primary keys ({{{pk}}} is a tuple) and for {{{db_default}}} PKs ({{{DatabaseDefault}}} is not {{{None}}}).
    22
    3 ```
     3{{{
    44>>> User() == User()
    55True
    66>>> User(tenant_id=1) == User(tenant_id=1)
    77True
    8 ```
     8}}}
    99
    10 Documented contract (and simple-PK behavior since #18864 / #18250) is that unsaved instances are equal only to themselves. `__hash__` already uses `_is_pk_set()` and raises for an unset PK.
     10Documented contract (and simple-PK behavior since #18864 / #18250) is that unsaved instances are equal only to themselves. {{{__hash__}}} already uses {{{_is_pk_set()}}} and raises for an unset PK.
    1111
    12 The XML serializer has the same leftover (`if obj.pk is not None`) and emits `pk='["None", "None"]'` for an unsaved composite instance instead of omitting the attribute.
     12The XML serializer has the same leftover ({{{if obj.pk is not None}}}) and emits {{{pk='["None", "None"]'}}} for an unsaved composite instance instead of omitting the attribute.
    1313
    14 Proposed fix: use `_is_pk_set()` in both places, matching `__hash__` and the rest of the #373 conversion.
     14Proposed fix: use {{{_is_pk_set()}}} in both places, matching {{{__hash__}}} and the rest of the #373 conversion.
    1515
    1616Related: #18864, #18250, #373.
Back to Top