diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ac99f..ca311cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +3.4.1 +----- +- Fix `dsv` decorator to work with `DSVError`. +- Fix dsv_feature `spec_name` should not show empty value. + + 3.4.0 ----- diff --git a/data_spec_validator/__version__.py b/data_spec_validator/__version__.py index f631007..da4564d 100644 --- a/data_spec_validator/__version__.py +++ b/data_spec_validator/__version__.py @@ -1 +1 @@ -__version__ = '3.4.0' +__version__ = '3.4.1' diff --git a/data_spec_validator/decorator/decorators.py b/data_spec_validator/decorator/decorators.py index 45ce6ae..25d5446 100644 --- a/data_spec_validator/decorator/decorators.py +++ b/data_spec_validator/decorator/decorators.py @@ -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 = { diff --git a/data_spec_validator/spec/features.py b/data_spec_validator/spec/features.py index 80524a7..422cb70 100644 --- a/data_spec_validator/spec/features.py +++ b/data_spec_validator/spec/features.py @@ -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: diff --git a/test/test_decorator_dj.py b/test/test_decorator_dj.py index e82d5e3..3ec5914 100644 --- a/test/test_decorator_dj.py +++ b/test/test_decorator_dj.py @@ -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 @@ -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]) diff --git a/test/test_decorator_drf.py b/test/test_decorator_drf.py index c813328..92f05f5 100644 --- a/test/test_decorator_drf.py +++ b/test/test_decorator_drf.py @@ -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 @@ -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])