-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Make Field constructors keyword-only #7632
Conversation
ffe82b8
to
25ead1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please fix the conflicts?
@auvipy Rebased. |
@auvipy Can we get this merged? :) |
I am not maintainer :D |
Fair. @tomchristie or someone else, can you take a look? |
Yup seems pretty reasonable. |
Based on past experience I'd expect that someone somewhere may well have some code updating to do after this change, but let's see. And yes it clearly makes sense. |
And there we go: fdb4931#r54532785 We might reconsider this given that we've already seen a user hit a pain point with the change, even without having released a new version. Unsure. |
documenting this would be the right choice, IMHO |
Cc @afparsons for having bumped into that issue in fdb4931#r54532785: I believe the change in this PR is net positive and will likely uncover some bugs in downstream code even if it might need some work to adapt. In that sense I agree with @auvipy that it'd be better to just document this loudly for the next release. |
This reverts commit fdb4931.
I'm extremely late to the party but this now makes unclear if this was intended -- but it certainly strikes me as odd |
see encode/django-rest-framework#7632 <!-- Describe your PR here. -->
see encode/django-rest-framework#7632 <!-- Describe your PR here. -->
Description
This PR makes the Field constructor keyword-only by adding a
*
(and turning*args, **kwargs
into just**kwargs
in subclasses). I don't believe anyone is (or should be) constructing fields asserializers.CharField(False, True, False, serializers.empty, ...)
The root issue this fixes is the nonobvious problem in e.g.
– you wouldn't expect that yields a non-validated read-only list field, would you? 😄 What happens is the positional
serializers.CharField()
argument gets passed up into theserializers.Field()
call as the first argument, which just so happens to beread_only
, and the field instance is a truthy value.../cc @magdapoppins for having initially bumped into this issue.