python-semanticversion icon indicating copy to clipboard operation
python-semanticversion copied to clipboard

Django model fields do not raise the correct error

Open daniboygg opened this issue 8 months ago • 0 comments

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.

daniboygg avatar Jun 27 '24 11:06 daniboygg