-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Propagate 'default' from model_field to serializer field #8130
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
Conversation
Fix encode#7469. Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
9333773
to
bbea2dc
Compare
I'll close my issue. |
Just a note for discussion, part of the motivating factor for this change was to include the default value in the If this PR gets merged, I can rework 8003 as its own PR. |
Hi folks. 👋 So, if we did want to accept this, then I'd suggest that this pull request should also update the OPTIONS responses in order to include the default - https://github.com/encode/django-rest-framework/blob/master/rest_framework/metadata.py#L115 Staying in line with how we generate django-rest-framework/rest_framework/schemas/openapi.py Lines 535 to 536 in 6ea95b6
I'm a bit reluctant, simply because at this point in it's lifecycle almost any change in REST framework ends up having unintended side-effects for existing users, and I could easily see this being the case for this change. We've used "default on the model => not required on the serializer" since ~forever. On the other hand, exposing default values on the schema and |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I think this may also fix #7489 which is still current. |
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.
the PR need to address following suggestion:
So, if we did want to accept this, then I'd suggest that this pull request should also update the OPTIONS responses in order to include the default - https://github.com/encode/django-rest-framework/blob/master/rest_framework/metadata.py#L115
Staying in line with how we generate 'default' for schemas would make sense...
django-rest-framework/rest_framework/schemas/openapi.py
Lines 535 to 536 in 6ea95b6
if field.default is not None and field.default != empty and not callable(field.default):
schema['default'] = field.default
I'm a bit reluctant, simply because at this point in it's lifecycle almost any change in REST framework ends up having unintended side-effects for existing users, and I could easily see this being the case for this change. We've used "default on the model => not required on the serializer" since ~forever.
On the other hand, exposing default values on the schema and OPTIONS responses does seem like an improvement.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
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.
I would like to see this rebased with a fresh approach to be considered to be accepted
Anyone should feel free to take over this PR. I’m not going to have time myself. |
@ashupednekar Do you have time for this? (Asking due to #7489 (comment)) |
@samims you can also check this out |
@auvipy I have made the changes requested in this PR.
I have created PR for this #9030 I can't update this PR as I don't have permission. |
Description
This is a resubmission of #8002 that will hopefully pass tests. The tl;dr is that field defaults are now propagated from models to model serializers.
Fix #7469.