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

ENUM_NAME_OVERRIDES not applying if choice values include a blank string as an option. #832

Closed
trumpet2012 opened this issue Oct 10, 2022 · 0 comments · Fixed by #833
Closed

Comments

@trumpet2012
Copy link
Contributor

trumpet2012 commented Oct 10, 2022

Describe the bug
ENUM_NAME_OVERRIDES is not using the custom name specified for the enum if the choice values include a blank string as an option.

This looks to be due to a difference in how the hashes are being computed for the choices in https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/plumbing.py#L778 and https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/hooks.py#L62.

When storing the overriden choice hash the null and blank values are included in the hashing, while when the choices are processed in the enum hook the null and blank values get excluded. This leads to the hash values not matching and the override not being detected.

To Reproduce
Create a choices objects that contains a blank string as a valid value.

// choices.py
class Answers(models.TextChoices):
    YES = "yes", "Yes"
    NO = "no", "No"
    UNSPECIFIED = "", ""
// settings.py
SPECTACULAR_SETTINGS = {
   ...
    "ENUM_NAME_OVERRIDES": {
        'YesNoAnswerEnum': "path.to.choices.Answers"
    }
}

Expected behavior
The name of the Answers choices in the schema should be YesNoAnswerEnum after applying the override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant