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

FuzzyDateFormField.__init__ should possibly also pop empty_value from kwargs #1

Open
ianmackinnon opened this issue Nov 4, 2024 · 0 comments

Comments

@ianmackinnon
Copy link

FuzzyDateFormField.__init__ currently pops max_length from kwargs because it may be set as a default by CharField.formfield, but is not valid for forms.MultiValueField.

Under certain circumstances, CharField.formfield also adds a default value for empty_value of None. This is similarly not valid for forms.MultiValueField and so should also probably be popped.

For reference, this is CharField.formfield as it stands in Django 5.1.2:

    def formfield(self, **kwargs):
        # Passing max_length to forms.CharField means that the value's length
        # will be validated twice. This is considered acceptable since we want
        # the value in the form field (to pass into widget for example).
        defaults = {"max_length": self.max_length}
        # TODO: Handle multiple backends with different feature flags.
        if self.null and not connection.features.interprets_empty_strings_as_nulls:
            defaults["empty_value"] = None
        defaults.update(kwargs)
        return super().formfield(**defaults)

I'd be happy to submit a PR with a fix if you'd like.

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

No branches or pull requests

1 participant