palewire / django-yamlfield

A Django database field for storing YAML data

Home Page:https://palewi.re/docs/django-yamlfield/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validation

justquick opened this issue · comments

Im modifying the YAMLField to include raising ValidationErrors when the yaml doesnt parse. I just subclassed the field but would be great to include this in the repo. It enabled the validation errors to populate up to the admin as form errors

from django.core.exceptions import ValidationError


class YAMLConfig(YAMLField):
    def to_python(self, value):
        try:
            return super().to_python(value)
        except Exception as exc:
            raise ValidationError(str(exc))

If you make a PR I'd be happy to include something like this, provided we could point to similar error handling the standard Django library.

I am closing this as inactive. If you have a PR you'd like to make, I'd welcome it.