Skip to content
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

Avoid ChoiceField duplicate enum values for allow_null, allow_blank #1085

Merged
merged 4 commits into from Oct 22, 2023

Conversation

intgr
Copy link
Contributor

@intgr intgr commented Oct 5, 2023

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).

@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (6e4180b) 98.57% compared to head (caf0a70) 98.57%.

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           
Files Coverage Δ
drf_spectacular/plumbing.py 97.07% <100.00%> (ø)
tests/test_plumbing.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@tfranzel tfranzel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tfranzel tfranzel merged commit 6e48a70 into tfranzel:master Oct 22, 2023
32 checks passed
@intgr intgr deleted the avoid-choicefield-duplicate-values branch October 22, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants