[Django]-Django strange SlugField validation, error not raised before clean(), uncleaned data returned

5👍

The clean() method is called after the field’s validator. If the alias is invalid, then it won’t be in cleaned_data. Your clean method should handle this case, for example:

def clean():
    cleaned_data = super().clean()
    print(self.errors)  # You should see the alias error here
    if 'alias' in cleaned_data:
        print(cleaned_data['alias'])
        # do any code that relies on cleaned_data['alias'] here
    return cleaned_data

See the docs on cleaning fields that depend on each other for more info.

Leave a comment