Changes between Version 2 and Version 3 of Ticket #35729, comment 2


Ignore:
Timestamp:
Sep 25, 2025, 10:17:06 AM (35 hours ago)
Author:
Jacob Walls

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #35729, comment 2

    v2 v3  
    11After further discussion on the [https://forum.djangoproject.com/t/how-to-serialize-user-profiles-without-natural-keys/34447 forum], and in a related ticket (#36225), I agree this is a usability bug in the serialization framework. The user model aspect is just orthogonal.
    22
    3 Django's pattern of calling `hasattr(obj, "natural_key")` is not subclass-friendly as pointed out above. There needs to be some way to ''cancel'' natural key serialization in a subclass and check for that. Maybe `def natural_key() -> tuple[str]` becomes `def natural_key() => tuple[str] | None`, and `hasattr(obj, "natural_key")` becomes some friendly wrapper for `getattr(obj, "natural_key", lambda obj: None)(obj) is not None`?
     3Django's pattern of calling `hasattr(obj, "natural_key")` is not subclass-friendly as pointed out above. There needs to be some way to ''cancel'' natural key serialization in a subclass and check for that. Maybe `def natural_key() -> tuple[str]` becomes `def natural_key() -> tuple[str] | None`, and `hasattr(obj, "natural_key")` becomes some friendly wrapper for `getattr(obj, "natural_key", lambda obj: None)(obj) is not None`?
Back to Top