Skip to content

Commit

Permalink
Merge pull request #79 from surenkov/feature/django-model-field-valid…
Browse files Browse the repository at this point in the history
…ation-error-with-plain-string-message

Use plain exception strings when throwing `django.core.exceptions.ValidationError`
  • Loading branch information
surenkov authored Jan 14, 2025
2 parents 0a0ba97 + 658b984 commit 48d42bc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: check-hooks-apply
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.3
rev: v0.9.1
hooks:
# Run the linter.
- id: ruff
Expand All @@ -17,4 +17,4 @@ repos:
# Run the formatter.
- id: ruff-format
files: "^django_pydantic_field/"
exclude: ^.*\b(\.pytest_cache|\.venv|venv).*\b.*$
exclude: ^.*\b(\.pytest_cache|\.venv|venv).*\b.*$
2 changes: 1 addition & 1 deletion django_pydantic_field/v1/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def to_python(self, value) -> "base.SchemaT":
assert self.decoder is not None
return self.decoder().decode(value)
except pydantic.ValidationError as e:
raise django_exceptions.ValidationError(e.errors())
raise django_exceptions.ValidationError(str(e)) from e

def get_prep_value(self, value):
if not self._is_prepared_schema:
Expand Down
3 changes: 1 addition & 2 deletions django_pydantic_field/v2/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ def to_python(self, value: ty.Any):
try:
return self.adapter.validate_python(value)
except pydantic.ValidationError as exc:
error_params = {"errors": exc.errors(), "field": self}
raise exceptions.ValidationError(exc.json(), code="invalid", params=error_params) from exc
raise exceptions.ValidationError(str(exc), code="invalid") from exc

def get_prep_value(self, value: ty.Any):
value = self._prepare_raw_value(value)
Expand Down

0 comments on commit 48d42bc

Please sign in to comment.