Skip to content

Commit e6e7412

Browse files
authored
Removed pdb/ipdb calls from API handlers (#243)
1 parent 69edcd2 commit e6e7412

File tree

8 files changed

+1
-92
lines changed

8 files changed

+1
-92
lines changed

lib/dl_api_commons/dl_api_commons/aio/middlewares/error_handling_outer.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def handle_error(
6767
elif isinstance(err, web.HTTPSuccessful):
6868
raise # noqa
6969
else:
70-
self.maybe_debug_catch(err)
7170
try:
7271
# TODO CONSIDER: Validate that response is serializable
7372
err_data = self._classify_error(err, request)
@@ -95,16 +94,6 @@ def handle_error(
9594
err_data,
9695
)
9796

98-
def maybe_debug_catch(self, err): # type: ignore # TODO: fix
99-
if os.environ.get("BI_ERR_PDB"):
100-
sys.last_traceback = err.__traceback__
101-
import traceback
102-
103-
traceback.print_exc()
104-
import ipdb
105-
106-
ipdb.pm()
107-
10897
def log_error_http_response( # type: ignore # TODO: fix
10998
self,
11099
err: Exception,

lib/dl_api_commons/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ readme = "README.md"
1313
aiohttp = ">=3.8.1"
1414
attrs = ">=22.2.0"
1515
flask = ">=2.2.5"
16-
ipdb = ">=0.13.13"
1716
marshmallow = ">=3.19.0"
1817
multidict = ">=4.0"
1918
opentracing = ">=2.4.0"

lib/dl_api_lib/dl_api_lib/api_decorators.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
status,
2828
)
2929
from dl_api_lib.schemas.main import get_api_model
30-
from dl_utils.utils import maybe_postmortem
3130

3231

3332
LOGGER = logging.getLogger(__name__)
@@ -153,7 +152,6 @@ def wrapper(*args, **kwargs): # type: ignore # TODO: fix
153152
if error_code is None:
154153
error_code = status.INTERNAL_SERVER_ERROR
155154
LOGGER.exception("Caught an exception in request handler")
156-
maybe_postmortem(ei=ei)
157155
else:
158156
LOGGER.info("Regular exception fired", exc_info=True)
159157

lib/dl_api_lib/dl_api_lib/app/data_api/resources/dataset/pivot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
generic_profiler_async,
2222
)
2323
from dl_query_processing.merging.primitives import MergedQueryDataStream
24-
from dl_utils.utils import exc_catch_awrap
2524

2625

2726
if TYPE_CHECKING:
@@ -49,7 +48,6 @@ class DatasetPivotView(DatasetDataBaseView):
4948
# responses={200: ('Success', dl_api_lib.schemas.data.DatasetVersionResultResponseSchema())}
5049
# )
5150
@generic_profiler_async("ds-pivot-full")
52-
@exc_catch_awrap
5351
@DatasetDataBaseView.with_resolved_entities
5452
@requires(RequiredResourceDSAPI.JSON_REQUEST)
5553
async def post(self) -> Response:

lib/dl_api_lib/dl_api_lib/app/data_api/resources/dataset/result.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
)
4444
from dl_query_processing.merging.primitives import MergedQueryDataStream
4545
from dl_query_processing.postprocessing.primitives import PostprocessedRow
46-
from dl_utils.utils import exc_catch_awrap
4746

4847

4948
if TYPE_CHECKING:
@@ -68,7 +67,6 @@ class DatasetResultView(DatasetDataBaseView, abc.ABC):
6867
# responses={200: ('Success', dl_api_lib.schemas.data.DatasetVersionResultResponseSchema())}
6968
# )
7069
@generic_profiler_async("ds-result-full")
71-
@exc_catch_awrap
7270
@DatasetDataBaseView.with_resolved_entities
7371
@requires(RequiredResourceDSAPI.JSON_REQUEST)
7472
async def post(self) -> Response:

lib/dl_core/dl_core/connection_executors/async_sa_executors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from dl_core.connection_models.common_models import TableDefinition
4747
from dl_core.db import SchemaInfo
4848
from dl_utils.aio import ContextVarExecutor
49-
from dl_utils.utils import maybe_postmortem
5049

5150

5251
if TYPE_CHECKING:

lib/dl_utils/dl_utils/utils.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import functools
66
from itertools import islice
77
import operator
8-
import os
9-
import sys
108
from time import time
119
from typing import (
1210
Any,
@@ -18,81 +16,11 @@
1816
Tuple,
1917
Type,
2018
TypeVar,
21-
cast,
2219
)
2320

2421
import attr
2522

2623

27-
def get_pdb() -> Any:
28-
try:
29-
import ipdb
30-
31-
return ipdb
32-
except Exception:
33-
import pdb
34-
35-
return pdb
36-
37-
38-
def maybe_postmortem(ei: Any = None) -> None:
39-
"""
40-
An env-controlled post-mortem breakpoint.
41-
Set `BI_ERR_PDB=1` to use.
42-
"""
43-
if ei is None:
44-
ei = sys.exc_info()
45-
if os.environ.get("BI_ERR_PDB") != "1":
46-
return
47-
_, _, sys.last_traceback = ei
48-
import traceback
49-
50-
print("".join(traceback.format_exception(*ei)))
51-
pdb = get_pdb()
52-
pdb.pm()
53-
54-
55-
_CALLABLE_TV = TypeVar("_CALLABLE_TV", bound=Callable)
56-
57-
58-
def exc_catch_wrap(func: _CALLABLE_TV) -> _CALLABLE_TV:
59-
"""
60-
An env-controlled post-mortem function wrapper.
61-
Set `BI_ERR_PDB=1` to use. Does nothing otherwise.
62-
"""
63-
if os.environ.get("BI_ERR_PDB") != "1":
64-
return func
65-
66-
@functools.wraps(func)
67-
def exc_catch_wrapped(*args: Any, **kwargs: Any) -> Any:
68-
try:
69-
return func(*args, **kwargs)
70-
except Exception:
71-
maybe_postmortem()
72-
raise
73-
74-
return cast(_CALLABLE_TV, exc_catch_wrapped)
75-
76-
77-
def exc_catch_awrap(afunc: _CALLABLE_TV) -> _CALLABLE_TV:
78-
"""
79-
An env-controlled post-mortem async-function wrapper.
80-
Set `BI_ERR_PDB=1` to use. Does nothing otherwise.
81-
"""
82-
if os.environ.get("BI_ERR_PDB") != "1":
83-
return afunc
84-
85-
@functools.wraps(afunc)
86-
async def exc_catch_awrapped(*args: Any, **kwargs: Any) -> Any:
87-
try:
88-
return await afunc(*args, **kwargs)
89-
except Exception:
90-
maybe_postmortem()
91-
raise
92-
93-
return cast(_CALLABLE_TV, exc_catch_awrapped)
94-
95-
9624
def get_type_full_name(t: Type) -> str:
9725
module = t.__module__
9826
qual_name = t.__qualname__

metapkg/poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)