Skip to content

Commit 5b742e2

Browse files
refactor lint
1 parent a5e3abb commit 5b742e2

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

app/decorators/mapper/exception_mapper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Decorators to rethrow and log exceptions."""
22

3+
import asyncio
34
from functools import wraps
45
from inspect import iscoroutinefunction
56
from typing import Any, Callable, Type
@@ -81,6 +82,9 @@ def _handle_exception_logic(
8182
args: tuple[Any, ...],
8283
kwargs: dict[str, Any],
8384
) -> None:
85+
if isinstance(exc, asyncio.CancelledError):
86+
raise
87+
8488
if exception_factory := self._get_exception_factory(type(exc)):
8589
context = ExceptionContext(exc, func, self._filtered_args(args), kwargs)
8690
raise exception_factory.make_exception(context) from exc

app/infrastructure/containers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22

33
from dependency_injector import containers, providers
4-
from dependency_injector.providers import Callable, Factory, Singleton
4+
from dependency_injector.providers import Callable, Factory
55
from httpx import AsyncClient, Limits
66
from pybotx import Bot, HandlerCollector
77
from redis import asyncio as aioredis

app/infrastructure/repositories/sample_record.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ async def create(self, record: SampleRecord) -> SampleRecord:
7272
.returning(SampleRecordModel)
7373
)
7474
result = await self._session.execute(query)
75-
await self._session.flush()
7675
record_model = result.scalar_one()
7776
return self._to_domain_object(record_model)
7877

@@ -91,7 +90,6 @@ async def update(self, record: SampleRecord) -> SampleRecord:
9190
.returning(SampleRecordModel)
9291
)
9392
execute_result = (await self._session.execute(query)).scalar_one_or_none()
94-
await self._session.flush()
9593
if execute_result is None:
9694
raise RecordDoesNotExistError(
9795
f"Sample record with id={record.id} does not exist."
@@ -125,8 +123,6 @@ async def delete(self, record_id: int) -> None:
125123
f"Sample record with id={record_id} does not exist."
126124
)
127125

128-
await self._session.flush()
129-
130126
@ExceptionMapper(
131127
{
132128
NoResultFound: EnrichedExceptionFactory(RecordDoesNotExistError),

app/infrastructure/worker/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from redis.asyncio import Redis
88
from saq import CronJob, Queue
99

10-
from app.infrastructure.containers import WorkerStartupContainer, BaseStartupContainer
10+
from app.infrastructure.containers import BaseStartupContainer, WorkerStartupContainer
1111
from app.infrastructure.worker.tasks.simple_task import heartbeat_task
1212
from app.logger import logger
1313
from app.settings import settings

app/presentation/bot/command_handlers/sample_record.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
SendErrorExplainToUserHandler,
1818
)
1919
from app.presentation.bot.error_handlers.exceptions_chain_executor import (
20-
DEFAULT_HANDLERS,
21-
ExceptionHandlersChainExecutor, DEFAULT_HANDLERS_WITH_EXPLAIN,
20+
DEFAULT_HANDLERS_WITH_EXPLAIN,
21+
ExceptionHandlersChainExecutor,
2222
)
2323
from app.presentation.bot.resources.strings import (
2424
SAMPLE_RECORD_CREATED_ANSWER,
@@ -48,9 +48,6 @@ class CreateSampleRecordHandler(BaseCommandHandler):
4848
}
4949
)
5050
]
51-
exception_handler_chain_executor = ExceptionHandlersChainExecutor(
52-
_EXCEPTIONS_HANDLERS
53-
)
5451

5552
def __init__(
5653
self,
@@ -62,7 +59,11 @@ def __init__(
6259
self._use_cases = use_case_factory
6360
self.unit_of_work = unit_of_work
6461

65-
super().__init__(bot, message, self.exception_handler_chain_executor)
62+
exception_handler_chain_executor = ExceptionHandlersChainExecutor(
63+
self._EXCEPTIONS_HANDLERS
64+
)
65+
66+
super().__init__(bot, message, exception_handler_chain_executor)
6667

6768
async def handle_logic(
6869
self,
@@ -94,9 +95,6 @@ class DeleteSampleRecordHandler(BaseCommandHandler):
9495
}
9596
)
9697
]
97-
exception_handler_chain_executor = ExceptionHandlersChainExecutor(
98-
_EXCEPTIONS_HANDLERS
99-
)
10098

10199
def __init__(
102100
self,
@@ -107,8 +105,11 @@ def __init__(
107105
):
108106
self._use_cases = use_case_factory
109107
self.unit_of_work = unit_of_work
108+
exception_handler_chain_executor = ExceptionHandlersChainExecutor(
109+
self._EXCEPTIONS_HANDLERS
110+
)
110111

111-
super().__init__(bot, message, self.exception_handler_chain_executor)
112+
super().__init__(bot, message, exception_handler_chain_executor)
112113

113114
async def handle_logic(
114115
self,
@@ -153,7 +154,11 @@ def __init__(
153154
self._use_cases = use_case_factory
154155
self.unit_of_work = unit_of_work
155156

156-
super().__init__(bot, message, self.exception_handler_chain_executor)
157+
exception_handler_chain_executor = ExceptionHandlersChainExecutor(
158+
self._EXCEPTIONS_HANDLERS
159+
)
160+
161+
super().__init__(bot, message, exception_handler_chain_executor)
157162

158163
async def handle_logic(
159164
self,

0 commit comments

Comments
 (0)