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

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

Open
mij opened this issue Sep 21, 2023 · 0 comments

Comments

@mij
Copy link

mij commented Sep 21, 2023

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.

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