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

Made VersionField raise correct Django exception #155

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions semantic_version/django_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import django
from django.db import models
from django.core.exceptions import ValidationError

if django.VERSION >= (3, 0):
# See https://docs.djangoproject.com/en/dev/releases/3.0/#features-deprecated-in-3-0
Expand Down Expand Up @@ -75,10 +76,14 @@ def to_python(self, value):
return value
if isinstance(value, base.Version):
return value
if self.coerce:
return base.Version.coerce(value, partial=self.partial)
else:
return base.Version(value, partial=self.partial)

try:
if self.coerce:
return base.Version.coerce(value, partial=self.partial)
else:
return base.Version(value, partial=self.partial)
except ValueError as e:
raise ValidationError(str(e)) from e


class SpecField(SemVerField):
Expand Down