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

BaseCSVField doesn't raise "required" error #869

Closed
neostimul opened this issue Jan 29, 2018 · 3 comments
Closed

BaseCSVField doesn't raise "required" error #869

neostimul opened this issue Jan 29, 2018 · 3 comments

Comments

@neostimul
Copy link

neostimul commented Jan 29, 2018

I create the filter with required DateField.

class SomeFilter(filters.FilterSet):
    class Meta:
        model = Data
        fields = {
            'date': ('range', ),
        }
        filter_overrides = {
             models.DateField: {
                 'filter_class': filters.DateFilter,
                 'extra': lambda f: {
                     'required': True,
                 },
             },
         }

But on validation stage BaseCSVField doesn't raise the required error, cause value is None and it just returns None, without cleaning the base class

class BaseCSVField(forms.Field):
    ....

    def clean(self, value):
        if value is None:
--->        return None
        return [super(BaseCSVField, self).clean(v) for v in value]
@neostimul neostimul changed the title BaseCSVField doesn't railse required error BaseCSVField doesn't raise "required" error Feb 5, 2018
@carltongibson
Copy link
Owner

Should be fixed by #854

@neostimul
Copy link
Author

Yes, it fixed. Thank you

@neostimul
Copy link
Author

neostimul commented Aug 2, 2018

No, i was wrong. BaseCSVField still does not raise required exception when date is not specified

when value is None (can be specified as None or not specified) must call clean value of Base class

    def clean(self, value):
        if value is None:
            value = super(BaseCSVField, self).clean(value)
            # or raise ValidationError(self.error_messages['required'], code='required')
        return [super(BaseCSVField, self).clean(v) for v in value]

or we have not required error

I mean work with this PR https://github.com/carltongibson/django-filter/pull/854/files
must be when required is True

with self.assertRaises(forms.ValidationError):
    self.field.clean(None)

I want to create a DateRangeFilter for random dates (example: /?date__range=[2018-01-01, 2018-02-02] )

I do

class DateRangeFilter(filters.BaseRangeFilter, filters.DateFilter):
    base_field_class = BaseRangeField

And have no raise reuired exception when /?date__range= or nothing params at all

May be i do something wrong.

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

2 participants