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

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

Open
devriez opened this issue May 16, 2022 · 0 comments
Open

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

devriez opened this issue May 16, 2022 · 0 comments

Comments

@devriez
Copy link

devriez commented May 16, 2022

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(....)?

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