Avoid ChoiceField duplicate enum values for allow_null, allow_blank#1085
Merged
tfranzel merged 4 commits intotfranzel:masterfrom Oct 22, 2023
Merged
Conversation
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1085 +/- ##
=======================================
Coverage 98.57% 98.57%
=======================================
Files 68 68
Lines 8426 8436 +10
=======================================
+ Hits 8306 8316 +10
Misses 120 120
☔ View full report in Codecov by Sentry. |
tfranzel
approved these changes
Oct 22, 2023
Owner
tfranzel
left a comment
There was a problem hiding this comment.
Excellent PR. Thanks @intgr
This is definitely an improvement to prevent useless duplication. However, I think it is generally bad form to explicitly include '' or None in the choice list, since this ought to be covered by the serializer/model field parameters. I don't remember how DRF handles this internally without looking it up, but this here is most likely the right thing to do (in the schema context) in either case.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using
ChoiceField(choices=[..., ''], allow_blank=True)then drf-spectacular would add another dupllicate''value into the schema.Same happens with
ChoiceField(choices=[..., None], allow_null=True).