From 6249e35f31b0a18d9b4b3f6a5c67fc0707dad2b7 Mon Sep 17 00:00:00 2001 From: ori roza Date: Sun, 12 May 2024 17:02:38 +0300 Subject: [PATCH 1/2] * no need to reconstruct the traceback --- drf_api_action/exceptions.py | 8 -------- drf_api_action/utils.py | 19 +++++-------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/drf_api_action/exceptions.py b/drf_api_action/exceptions.py index 166b77f..a86836a 100644 --- a/drf_api_action/exceptions.py +++ b/drf_api_action/exceptions.py @@ -1,10 +1,2 @@ class ActionsAPIException(RuntimeError): pass - - -class ActionsAPIExceptionMiddleware: - def __new__(cls, *args, **kwargs): - error_type = kwargs.pop('error_type', Exception) - error = error_type(*args) - error.__traceback__ = kwargs.pop('traceback', error_type.__traceback__) - return error diff --git a/drf_api_action/utils.py b/drf_api_action/utils.py index 366d74e..367ed07 100644 --- a/drf_api_action/utils.py +++ b/drf_api_action/utils.py @@ -1,5 +1,4 @@ from typing import Optional -from drf_api_action.exceptions import ActionsAPIExceptionMiddleware class CustomRequest: @@ -27,19 +26,11 @@ def run_as_api(self, func, serializer_class, *args, **kw): self.kwargs = kw # adding our enhanced kwargs into instance kwargs self.request = request # mocking request with our arguments as data in the instance - try: - ret = func(request, **kw) - if isinstance(ret.data, list): # multiple results - results = [dict(res) for res in ret.data] - else: # only one json - results = {k.lower(): v for k, v in ret.data.items()} - except Exception as error: # pylint: disable=broad-except - error_type = type(error) - # re-constructing the error with the actual traceback - raised_exception = ActionsAPIExceptionMiddleware(*error.args, - error_type=error_type, - traceback=error.__traceback__) # fixing stack frames - raise raised_exception # pylint: disable=raising-non-exception + ret = func(request, **kw) # evaluating endpoint + if isinstance(ret.data, list): # multiple results + results = [dict(res) for res in ret.data] + else: # only one json + results = {k.lower(): v for k, v in ret.data.items()} return results From f4d7bbc6d0bf2f1a41d84195ffbdfaa046a25d5a Mon Sep 17 00:00:00 2001 From: ori roza Date: Sun, 12 May 2024 17:03:16 +0300 Subject: [PATCH 2/2] version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2669fc2..01a0297 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "drf_api_action" -version = "1.2.1" +version = "1.2.2" description = "drf-api-action elevates DRF testing by simplifying REST endpoint testing to a seamless, function-like experience." readme = "README.md" authors = ["Ori Roza "]