Skip to content

django-parler does not honor validators attribute -- validation possible at all? #342

@mij

Description

@mij

Hello folks,

I applied validators=[myfun] to a TranslatedFields's field today. It looked like this:

def validate_commonmark(value: str) -> str:
    raise ValidationError("I don't like anything")

class MyModel(TranslatableModel):
    name = models.SlugField(primary_key=True)

    translations = TranslatedFields(
        description = models.TextField(validators=[validate_commonmark]),
    )

The validators field is ignored – i.e. calling MyModel(name='foo', description='bar').full_clean() is always accepted.

The only way I found to get validation to work was the following:

class MyModel(TranslatableModel):
    name = models.SlugField(primary_key=True)

    translations = TranslatedFields(
        description = models.TextField(),
    )

    def clean(self):
        self.description = validate_commonmark(self.description)

The downside of this obviously being that validation errors are no longer linked to the affected field. I was surprised to find no mention of this limitation in the documentation nor online.

I had no success locating the issue in the limited time I put into looking at parler's code -- my bad.

If there's any guidance into where the problem lies, and the solution isn't a major refact, I'm happy to look into it and contribute a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions