Skip to content

Conversation

@emmanuel-ferdman
Copy link
Contributor

PR Summary

prefetch_related_objects and aprefetch_related_objects were typed to accept Iterable[Model], but Django's implementation uses obj_list[0] indexing internally, which requires a Sequence. Passing a set or frozenset would pass type checking but crash at runtime with TypeError: 'set' object is not subscriptable. This PR changes the parameter type to Sequence[Model] to match the actual runtime requirement.

Fixes #2948

Copy link
Contributor

@UnknownPlatypus UnknownPlatypus left a comment

Choose a reason for hiding this comment

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

Thanks for the pr, I've left a few comments

@UnknownPlatypus
Copy link
Contributor

Thanks!

@UnknownPlatypus UnknownPlatypus merged commit aa98be2 into typeddjango:master Dec 25, 2025
46 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.

prefetch_related_objects cannot work with Iterables - it is expecting a Sequence

2 participants