From 93540b34d4ef46f68df2c8bfe90447d0f649a852 Mon Sep 17 00:00:00 2001 From: rimi0108 Date: Sat, 4 Oct 2025 13:52:59 +0900 Subject: Fixed #35729 -- Enabled natural key serialization opt-out for subclasses. Refactored serialization logic to allow models inheriting a natural_key() method (e.g. AbstractBaseUser) to explicitly opt out of natural key serialization by returning an empty tuple from the method. Thanks Jonas Dittrich for the report. Co-authored-by: Jacob Walls --- docs/topics/serialization.txt | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'docs/topics') diff --git a/docs/topics/serialization.txt b/docs/topics/serialization.txt index 2b28f5e15a..f801df0561 100644 --- a/docs/topics/serialization.txt +++ b/docs/topics/serialization.txt @@ -638,6 +638,15 @@ command line flags to generate natural keys. natural keys during serialization, but *not* be able to load those key values, just don't define the ``get_by_natural_key()`` method. +Subclasses can opt out of natural key serialization by returning an empty tuple +(``()``) from ``natural_key()``. This tells the serializer to fall back to +the standard primary key. + +.. versionchanged:: 6.1 + + Support for opting out of natural key serialization by returning an empty + tuple was added. + .. _natural-keys-and-forward-references: Natural keys and forward references -- cgit v1.3