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

fix: DSVError are not JSON serializable #42

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion data_spec_validator/decorator/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _get_error_response(error, use_drf):
Return the error response based on the error type.
If the attribute use_drf is True, Raise DRF's exception to let DRF's exception handler do something about it.
"""
error_msg = {'messages': error.message}
error_msg = {'messages': [str(err) for err in error.message]}

if use_drf:
err_map = {
Expand Down
4 changes: 3 additions & 1 deletion data_spec_validator/spec/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def wrap(cls: Type) -> Type:


def get_spec_name(spec) -> str:
return getattr(spec, _FEAT_PARAMS).spec_name if hasattr(spec, _FEAT_PARAMS) else spec.__name__
if hasattr(spec, _FEAT_PARAMS) and getattr(spec, _FEAT_PARAMS).spec_name:
return getattr(spec, _FEAT_PARAMS).spec_name
return spec.__name__


def get_err_mode(spec) -> ErrorMode:
Expand Down
3 changes: 2 additions & 1 deletion test/test_decorator_dj.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from data_spec_validator.decorator import dsv, dsv_request_meta
from data_spec_validator.decorator.decorators import ParseError
from data_spec_validator.spec import DIGIT_STR, LIST_OF, ONE_OF, STR, Checker, dsv_feature
from data_spec_validator.spec import DIGIT_STR, LIST_OF, ONE_OF, STR, Checker, ErrorMode, dsv_feature

from .utils import is_django_installed, make_request

Expand Down Expand Up @@ -223,6 +223,7 @@ def decorated_func(self, request, field_a):

def test_json_response_content(self):
# arrange
@dsv_feature(err_mode=ErrorMode.ALL)
class _ViewSpec:
named_arg = Checker([DIGIT_STR])

Expand Down
3 changes: 2 additions & 1 deletion test/test_decorator_drf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from parameterized import parameterized

from data_spec_validator.decorator import dsv, dsv_request_meta
from data_spec_validator.spec import DIGIT_STR, LIST_OF, ONE_OF, STR, Checker, dsv_feature
from data_spec_validator.spec import DIGIT_STR, LIST_OF, ONE_OF, STR, Checker, ErrorMode, dsv_feature

from .utils import is_drf_installed, make_request

Expand Down Expand Up @@ -178,6 +178,7 @@ def decorated_func(self, request, field_a):

def test_json_response_content(self):
# arrange
@dsv_feature(err_mode=ErrorMode.ALL)
class _ViewSpec:
field_a = Checker([DIGIT_STR])

Expand Down
Loading