Skip to content

Django model fields do not raise the correct error #157

@daniboygg

Description

@daniboygg

VersionField and SpecField both raise a ValueError exception when an incorrect value is passed to Version constructor or BaseSpec.parse function.

The documentation in django for create custom models fields says https://docs.djangoproject.com/en/5.0/howto/custom-model-fields/#converting-values-to-python-objects:

For to_python(), if anything goes wrong during value conversion, you should raise a ValidationError exception.

I discover this error making a ModelForm from a model that included a VersionField field. Raising a ValueError makes the form crash instead of handle the error gracefully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions