Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: model serializer instance should not be sequence #719

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JoshFerge
Copy link

fixes #718

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

@JoshFerge
Copy link
Author

I could not find any Sequence usages in https://github.com/encode/django-rest-framework/blob/master/rest_framework/serializers.py

Thanks!

just fixed the type ignore error in ci

@intgr
Copy link
Contributor

intgr commented Jan 13, 2025

instance is a sequence when the serializer is initialized with many=True. Although it truly is annoying to deal with.

There was a plan to fix this with an overloaded Serializer __new__ method, but it requires changes to mypy:

@JoshFerge
Copy link
Author

got it. thanks for clarifying! will close.

@JoshFerge
Copy link
Author

JoshFerge commented Jan 21, 2025

Re-opening, as I think that internally the type will never be a sequence, as the new function will return a ListSerializer if a sequence is passed in. I think this is correct.

As written, the serializer is impossible to write a subclass for. cc @intgr @sobolevn

@intgr
Copy link
Contributor

intgr commented Jan 25, 2025

Sorry for the lack of reply. It's a tricky decision between two bad options and I've been pondering this in the background. I'm rather inclined to merge this.

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.

Incorrect Type Hint for ModelSerializer class instance attribute
3 participants