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

Handle unset fields with 'many=True'#7574

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
tomchristie merged 2 commits intoencode:masterfromstephenfin:issue/7550
Jun 8, 2022

Conversation

stephenfin
Copy link
Contributor

@stephenfinstephenfin commentedOct 3, 2020
edited
Loading

The docs note:

When serializing fields with dotted notation, it may be necessary to
provide adefault value if any object is not present or is empty
during attribute traversal.

However, this doesn't work for fields withmany=True. When using these, the default is simply ignored.

The solution is simple: do inManyRelatedField what we were already doing forField, namely, catch possibleAttributeError andKeyError exceptions and return the default if there is one set.

I still need to add tests. Input here would be appreciated 😄

Refs:#7550

The docs note:  When serializing fields with dotted notation, it may be necessary to  provide a `default` value if any object is not present or is empty  during attribute traversal.However, this doesn't work for fields with 'many=True'. When usingthese, the default is simply ignored.The solution is simple: do in 'ManyRelatedField' what we were alreadydoing for 'Field', namely, catch possible 'AttributeError' and'KeyError' exceptions and return the default if there is one set.Signed-off-by: Stephen Finucane <stephen@that.guru>Closes:encode#7550
Signed-off-by: Stephen Finucane <stephen@that.guru>
@stephenfin
Copy link
ContributorAuthor

Bump. Is there anything else I need to do to get eyes on this? Happy to propose backports to stable branches after the fact too.

stephenfin added a commit to getpatchwork/patchwork that referenced this pull requestDec 13, 2020
This wasn't writeable for reasons I haven't been able to figure out.However, it's not actually needed: the 'PatchSerializer' can do the jobjust fine, given enough information. This exposes a bug in DRF, whichhas been reported upstream [1]. While we wait for that fix, or somevariant of it, to be merged, we must monkey patch the library.[1]encode/django-rest-framework#7550[2]encode/django-rest-framework#7574Signed-off-by: Stephen Finucane <stephen@that.guru>Reported-by: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>Closes:#379Cc: Daniel Axtens <dja@axtens.net>Cc: Rohit Sarkar <rohitsarkar5398@gmail.com>
stephenfin added a commit to getpatchwork/patchwork that referenced this pull requestDec 13, 2020
This wasn't writeable for reasons I haven't been able to figure out.However, it's not actually needed: the 'PatchSerializer' can do the jobjust fine, given enough information. This exposes a bug in DRF, whichhas been reported upstream [1]. While we wait for that fix, or somevariant of it, to be merged, we must monkey patch the library.Conflicts:patchwork/api/patch.pyNOTE(stephenfin): Conflicts are due to the absence of commitd3d4f9f("Add Django 3.0 support") which we do not want to backport here.[1]encode/django-rest-framework#7550[2]encode/django-rest-framework#7574Signed-off-by: Stephen Finucane <stephen@that.guru>Reported-by: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>Closes:#379Cc: Daniel Axtens <dja@axtens.net>Cc: Rohit Sarkar <rohitsarkar5398@gmail.com>(cherry picked from commitfe07f30)
@stale
Copy link

stalebot commentedApr 30, 2022

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.

@stalestalebot added the stale labelApr 30, 2022
@stephenfin
Copy link
ContributorAuthor

Bump

@stalestalebot removed the stale labelMay 2, 2022
@tomchristie
Copy link
Member

Verified to myself that this brings the behaviour into line withwhat we do inField, yup.

We'd normally be risk-averse to a moderately impactful change like this,but because it only changes behaviour in the case of exceptions, this seems like a clear improvement/bug fix to me.

So, yes, let's go with it.

Thanks & appreciate your patience.

stephenfin reacted with hooray emoji

@tomchristietomchristie merged commit5185cc9 intoencode:masterJun 8, 2022
@stephenfinstephenfin deleted the issue/7550 branchJune 8, 2022 14:59
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull requestDec 3, 2022
* Handle unset fields with 'many=True'The docs note:  When serializing fields with dotted notation, it may be necessary to  provide a `default` value if any object is not present or is empty  during attribute traversal.However, this doesn't work for fields with 'many=True'. When usingthese, the default is simply ignored.The solution is simple: do in 'ManyRelatedField' what we were alreadydoing for 'Field', namely, catch possible 'AttributeError' and'KeyError' exceptions and return the default if there is one set.Signed-off-by: Stephen Finucane <stephen@that.guru>Closes:encode#7550* Add test cases forencode#7550Signed-off-by: Stephen Finucane <stephen@that.guru>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@stephenfin@tomchristie

[8]ページ先頭

©2009-2025 Movatter.jp