Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Propagate 'default' from model_field to serializer field.#9030

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
auvipy merged 10 commits intoencode:masterfromrnshaikh:model-serializer-defaults
Aug 7, 2023

Conversation

rnshaikh
Copy link
Contributor

@rnshaikhrnshaikh commentedJul 1, 2023
edited by auvipy
Loading

This is PR for changes requested in PR#8130.
default fields propagated from model to serializers.

  1. Generate 'default' for serializer as generated for openapi schema.
  2. Updated OPTIONS response to accommodate default field there. created Testcase to check default is generated for OPTIONS response for different field.

fixes#7469

sevdog reacted with thumbs up emoji
john-partonand others added2 commitsJune 24, 2023 16:07
Fixencode#7469.Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
@auvipyauvipy self-requested a reviewJuly 2, 2023 07:42
@auvipyauvipy added this to the3.15 milestoneJul 2, 2023
@auvipy
Copy link
Member

I think we should also document the intended side effect for this change

@rnshaikh
Copy link
ContributorAuthor

@auvipy Okay. should i create list of side effects?

@auvipy
Copy link
Member

that would be great

@auvipy
Copy link
Member

Hey Rizwan! would be great if you could revisit this and add some docs on the intended side effects topic here

@auvipy
Copy link
Member

this is the only remaining issue to get merged for 3.15 releasehttps://github.com/encode/django-rest-framework/milestones/3.15

@rnshaikh
Copy link
ContributorAuthor

@auvipy apologize for delay.
I have gone through the effects of these changes. find following points.

  1. all default value of model will be pass as default to serializer and to the options method.
  2. if the default is callable then it is not propagated in options.
  3. if the default is callable is not propagated but value will be evaluated each time it is used.
  4. if the value is not given then default value will be present in serializer also avaliable in serializer's methods.
  5. if the value is not given specified validation on given field will be evaluted on default value as that field will be present in serializer.

@auvipy
Copy link
Member

can you please add them as a note in the relevant doc section?

@auvipyauvipy requested a review froma teamJuly 31, 2023 03:53
@rnshaikh
Copy link
ContributorAuthor

rnshaikh commentedJul 31, 2023
edited
Loading

@auvipy I have added notes regarding default value propagation from model to serializer in default argument section of serializer field

@auvipyauvipy requested a review froma teamAugust 2, 2023 05:32
@auvipyauvipy merged commit7a9db57 intoencode:masterAug 7, 2023
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 18, 2024
DRF verson 3.15 propagate 'default' from model field to serializer.encode/django-rest-framework#9030
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 18, 2024
DRF verson 3.15 propagate 'default' from model field to serializer.encode/django-rest-framework#9030
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 18, 2024
DRF verson 3.15 propagate 'default' from model field to serializer.encode/django-rest-framework#9030
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 18, 2024
DRF verson 3.15 propagate 'default' from model field to serializer.encode/django-rest-framework#9030
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 18, 2024
DRF verson 3.15 propagate 'default' from model field to serializer.encode/django-rest-framework#9030
tomchristie added a commit that referenced this pull requestMar 21, 2024
auvipy pushed a commit that referenced this pull requestMar 22, 2024
* Revert#9030* Fix test case
@vignirvignir
Copy link

Hi!

After upgrading from DRF 3.14 to 3.15 our tests broke when a model serializer that allows required=False for a non-nullable field in the corresponding model is now ignored so the endpoint that uses the serializer to create the object throws an error claiming you need to provide the value for the field.

However, the value that eventually goes into the field of the model might be managed in the create method of the serializer and set there.

In this example there is an entity_id field that refers to an entity field on the model. The entity_id does not need to be provided by the user as other information are used to create the Entity objects and assign to the entity field of the Customer model in the create method of the serializer.

class CustomerDetailSerializer(serializers.ModelSerializer):    entity_id = EntityForeignKey(source="entity", write_only=True, allow_null=True, required=False)class Customer(models.Model):    entity = models.ForeignKey("users.Entity", related_name="customers", on_delete=models.PROTECT)

kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 25, 2024
As DRFencode/django-rest-framework#9030 hasbeen reverted in 3.15.1, the related hack is no longer needed.
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 25, 2024
As DRFencode/django-rest-framework#9030 hasbeen reverted in 3.15.1, the generated openAPI schema is missing defaultvalues, which might be revelant in the documentation.
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 25, 2024
As DRFencode/django-rest-framework#9030 hasbeen reverted in 3.15.1, the related hack is no longer needed.
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 25, 2024
As DRFencode/django-rest-framework#9030 hasbeen reverted in 3.15.1, the generated openAPI schema is missing defaultvalues, which might be revelant in the documentation.
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 26, 2024
As DRFencode/django-rest-framework#9030 hasbeen reverted in 3.15.1, the related hack is no longer needed.
kernicPanel added a commit to openfun/joanie that referenced this pull requestMar 26, 2024
As DRFencode/django-rest-framework#9030 hasbeen reverted in 3.15.1, the generated openAPI schema is missing defaultvalues, which might be revelant in the documentation.
parasgupta-jtg added a commit to joshtechnologygroup/django-rest-framework that referenced this pull requestMar 3, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sshishovsshishovsshishov left review comments

@auvipyauvipyauvipy approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
3.15
Development

Successfully merging this pull request may close these issues.

ModelSerializer generate ChoicesField will discard default parameter
5 participants
@rnshaikh@auvipy@vignirvignir@sshishov@john-parton

[8]ページ先頭

©2009-2025 Movatter.jp