From 7665087bd96018e52a1b1cb02d67642c1efa7359 Mon Sep 17 00:00:00 2001 From: rimi0108 Date: Fri, 14 Nov 2025 19:46:54 +0900 Subject: [PATCH] Refs #35729 -- Refactor natural key retrieval to streamline callable checks in Serializer. --- django/core/serializers/base.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py index 1ddf3b8742..cc29cce6ed 100644 --- a/django/core/serializers/base.py +++ b/django/core/serializers/base.py @@ -240,14 +240,10 @@ class Serializer: """ Return a natural key tuple for the given object when available. """ - if not obj: + if not (obj and callable(getattr(obj, "natural_key", None))): return None - natural_key_func = getattr(obj, "natural_key", None) - if not callable(natural_key_func): - return None - - natural_key_value = natural_key_func() + natural_key_value = obj.natural_key() if self._is_natural_key_opt_out(natural_key_value): return None