rbarrois / python-semanticversion

Semantic version comparison for Python (see http://semver.org/)
BSD 2-Clause "Simplified" License
281 stars 74 forks source link

Django model fields do not raise the correct error #157

Open daniboygg opened 4 months ago

daniboygg commented 4 months ago

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.