Changes between Initial Version and Version 1 of Ticket #37309
- Timestamp:
- Aug 31, 2026, 11:00:05 AM (109 minutes ago)
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}}}). 2 2 3 ``` 3 {{{ 4 4 >>> User() == User() 5 5 True 6 6 >>> User(tenant_id=1) == User(tenant_id=1) 7 7 True 8 ``` 8 }}} 9 9 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.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. 11 11 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.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. 13 13 14 Proposed fix: use `_is_pk_set()` in both places, matching `__hash__`and the rest of the #373 conversion.14 Proposed fix: use {{{_is_pk_set()}}} in both places, matching {{{__hash__}}} and the rest of the #373 conversion. 15 15 16 16 Related: #18864, #18250, #373.