Refs #35729 -- Refactor natural key retrieval to streamline callable checks in Serializer.

This commit is contained in:
rimi0108 2025-11-14 19:46:54 +09:00
parent 06f6cc1ec6
commit 7665087bd9

View file

@ -240,14 +240,10 @@ class Serializer:
""" """
Return a natural key tuple for the given object when available. 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 return None
natural_key_func = getattr(obj, "natural_key", None) natural_key_value = obj.natural_key()
if not callable(natural_key_func):
return None
natural_key_value = natural_key_func()
if self._is_natural_key_opt_out(natural_key_value): if self._is_natural_key_opt_out(natural_key_value):
return None return None