Skip to content

pics app | return from method clean() in CreateForm #34

@devriez

Description

@devriez

Hi, i am new here. So be kind to me if I wrote stupidity)
But it's look like you forgot to return clean_data from method clean() in pics/forms.py/CreateForm

according to documentation:

The clean() method on a Field subclass is responsible for running to_python(), validate(), and run_validators() in the correct order and propagating their errors. If, at any time, any of the methods raise ValidationError, the validation stops and that error is raised. This method returns the clean data, which is then inserted into the cleaned_data dictionary of the form.

` Now it's:

def clean(self):
    cleaned_data = super().clean()
    pic = cleaned_data.get('picture')
    if pic is None:
        return
    if len(pic) > self.max_upload_limit:
        self.add_error('picture', "File must be < "+self.max_upload_limit_text+" bytes")`

Also we can see that super().clean() return clean_data

` May be it should be like this:

def clean(self):
    cleaned_data = super().clean()
    pic = cleaned_data.get('picture')
    if pic is None:
        return clean_data
    if len(pic) > self.max_upload_limit:
        self.add_error('picture', "File must be < "+self.max_upload_limit_text+" bytes")
    return clean_data`

p.s. may be it should also raise ValidationError after self.add_error(....)? Otherwise how is_valid() will know about error. Or it will take information from self.add_error(....)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions