Skip to content

Conversation

@emmanuel-ferdman
Copy link
Contributor

PR Summary

This PR adjusts the typing for relational serializer fields so they return the actual model instances or the lightweight PKOnlyObject Django REST Framework sometimes uses, instead of the already-serialized values. This matches DRF’s real behavior: get_attribute hands to_representation either the full object or the PK-only placeholder, so the new annotations describe exactly what callers receive and avoid type errors when the optimization kicks in.

Fixes #829.

@intgr intgr self-assigned this Oct 19, 2025
Copy link
Contributor

@intgr intgr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! After the latest changes, this makes sense to me.

@intgr intgr changed the title Fix Field.get_attribute stub signature Fix Field.get_attribute() return and RelatedField.to_representation() parameter for PKOnlyObject Oct 20, 2025
@intgr intgr merged commit 3dc240a into typeddjango:master Oct 20, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Wrong return type for Field.get_attribute()

4 participants