$ the-wire · showcase
Django fixes equality and XML serialization for unsaved composite primary keys
By RepoJournal · Filed · About Django
Django's Model.__eq__ and XML serializer now use _is_pk_set() to correctly handle unsaved instances with composite or db_default primary keys.
Django fixed ticket #37309 by switching Model.__eq__ and the XML serializer from `pk is None` to `_is_pk_set()` [1][2][3]. Previously, unsaved instances with composite or db_default primary keys compared equal because their pk values are tuples like `(None, None)` or `DatabaseDefault`, not None. This is a subtle but important fix for code that relies on equality to distinguish unsaved model instances. The same change also stops the XML serializer from emitting a dummy pk attribute for such unsaved instances, cleaning up serialized output [3]. The djangoproject.com team removed a duplicate "Back to top" link from the Sponsor page, which was already provided by the base template [4]. A benchmark bot added results for ubuntu-latest to django-asv [5].
Action items
- → Review any code that compares unsaved model instances for equality, especially with composite or db_default primary keys, and test after upgrading. django/django [plan]
- → Check XML serialization output for unsaved models with composite primary keys after upgrading to ensure no dummy pk attributes appear. django/django [plan]
- → Monitor django-asv benchmark results for ubuntu-latest and watch for regressions. django/django-asv [monitor]
References
- [1] Fixed #37309 -- Used _is_pk_set() in Model.__eq__ and the XML serializer. ↗ django/django
- [2] Fixed #37309 -- Used _is_pk_set() in Model.__eq__. ↗ django/django
- [3] Refs #37309 -- Used _is_pk_set() in the XML serializer. ↗ django/django
- [4] Removed duplicate "Back to top" link from Sponsor page. (#2814) ↗ django/djangoproject.com
- [5] Results for ubuntu-latest added [skip ci] ↗ django/django-asv