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

[#31] Bypass validation of defaults for Django fields containing choices #36

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

swrichards
Copy link
Contributor

@swrichards swrichards commented Dec 17, 2024

The reason here is that the source of our config values cannot
express complex types such as enum members, and that defaults
for Django fields with choices frequently include such types
(or callables returning such types). We are mainly about the
types of the values provided from outside, not of Django field
defaults (beyond null and blank), so we can leave the validation
of the default to Django.

@swrichards swrichards linked an issue Dec 17, 2024 that may be closed by this pull request
@swrichards swrichards force-pushed the 31-literal-default-values branch 2 times, most recently from d210fc0 to 8f310c4 Compare December 17, 2024 12:41
The reason here is that the source of our config values cannot
express complex types such as enum members, and that defaults
for Django fields with choices frequently include such types
(or callables returning such types). We are mainly about the
types of the values provided from outside, not of Django field
defaults (beyond null and blank), so we can leave the validation
of the default to Django.
@swrichards swrichards force-pushed the 31-literal-default-values branch from 8f310c4 to fab1ad8 Compare December 17, 2024 12:52
@swrichards swrichards marked this pull request as ready for review December 17, 2024 13:03
@swrichards swrichards requested a review from stevenbal December 17, 2024 13:03
Comment on lines +28 to +29
str_with_choices_and_incorrectly_typed_default = models.CharField(
max_length=3, choices=StrChoices.choices, default=1974
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intentional that this is a CharField with an int default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, that's because the test has to validate that the default is not validated (I hope the name will provide sufficient hint that this was not an oversight).

@swrichards swrichards merged commit 751557a into main Dec 17, 2024
17 checks passed
@stevenbal stevenbal deleted the 31-literal-default-values branch December 20, 2024 11:43
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.

Default values for choices should be converted to literals
2 participants