mirror of
https://github.com/django/django.git
synced 2025-11-19 11:15:44 +00:00
Refs #35729 -- Refactor natural key retrieval to streamline callable checks in Serializer.
This commit is contained in:
parent
06f6cc1ec6
commit
7665087bd9
1 changed files with 2 additions and 6 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue