Skip to content

Commit 906b937

Browse files
author
Sergio García Prado
committed
ISSUE #98
* Add `ProgrammingException`. * Rename `UnableToConnectException` as `ConnectionException`.
1 parent d23f845 commit 906b937

File tree

15 files changed

+88
-50
lines changed

15 files changed

+88
-50
lines changed

packages/core/minos-microservice-aggregate/minos/aggregate/snapshots/repositories/database/impl.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
DatabaseMixin,
2020
Inject,
2121
NotProvidedException,
22+
ProgrammingException,
2223
import_module,
2324
)
2425

@@ -152,10 +153,10 @@ async def _load_offset(self) -> int:
152153
operation = self.operation_factory.build_query_offset()
153154
# noinspection PyBroadException
154155
try:
155-
raw = await self.submit_query_and_fetchone(operation)
156-
return raw[0]
157-
except Exception:
156+
row = await self.submit_query_and_fetchone(operation)
157+
except ProgrammingException:
158158
return 0
159+
return row[0]
159160

160161
async def _store_offset(self, offset: int) -> None:
161162
operation = self.operation_factory.build_submit_offset(offset)

packages/core/minos-microservice-aggregate/minos/aggregate/transactions/repositories/database/impl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from minos.common import (
1111
Config,
1212
DatabaseMixin,
13+
ProgrammingException,
1314
)
1415

1516
from ....exceptions import (
@@ -44,7 +45,7 @@ async def _submit(self, transaction: TransactionEntry) -> TransactionEntry:
4445

4546
try:
4647
updated_at = await self.submit_query_and_fetchone(operation)
47-
except StopAsyncIteration:
48+
except ProgrammingException:
4849
raise TransactionRepositoryConflictException(
4950
f"{transaction!r} status is invalid respect to the previous one."
5051
)

packages/core/minos-microservice-aggregate/tests/test_aggregate/test_snapshots/test_repositories/test_database.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from minos.common import (
2323
DatabaseClient,
2424
NotProvidedException,
25+
ProgrammingException,
2526
classname,
2627
current_datetime,
2728
)
@@ -58,7 +59,7 @@ async def synchronize(self):
5859
DatabaseClient,
5960
"fetch_one",
6061
side_effect=[
61-
StopAsyncIteration,
62+
ProgrammingException(""),
6263
(current_datetime(), current_datetime()),
6364
(current_datetime(), current_datetime()),
6465
(current_datetime(), current_datetime()),
@@ -232,7 +233,7 @@ async def test_dispatch_ignore_previous_version(self):
232233
DatabaseClient,
233234
"fetch_one",
234235
side_effect=[
235-
StopAsyncIteration,
236+
ProgrammingException(""),
236237
(current_datetime(), current_datetime()),
237238
(current_datetime(), current_datetime()),
238239
(9999,),

packages/core/minos-microservice-aggregate/tests/test_aggregate/test_transactions/test_repositories/test_database.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
from minos.aggregate import (
77
DatabaseTransactionRepository,
88
TransactionRepository,
9-
TransactionRepositoryConflictException,
109
TransactionStatus,
1110
)
1211
from minos.aggregate.testing import (
1312
TransactionRepositoryTestCase,
1413
)
1514
from minos.common import (
1615
DatabaseClient,
16+
ProgrammingException,
1717
current_datetime,
1818
)
1919
from tests.utils import (
@@ -48,10 +48,10 @@ async def test_submit_pending_raises(self):
4848
"fetch_one",
4949
side_effect=[
5050
(current_datetime(),),
51-
TransactionRepositoryConflictException(""),
52-
TransactionRepositoryConflictException(""),
53-
TransactionRepositoryConflictException(""),
54-
TransactionRepositoryConflictException(""),
51+
ProgrammingException(""),
52+
ProgrammingException(""),
53+
ProgrammingException(""),
54+
ProgrammingException(""),
5555
],
5656
):
5757
await super().test_submit_pending_raises()
@@ -62,10 +62,10 @@ async def test_submit_reserving_raises(self):
6262
"fetch_one",
6363
side_effect=[
6464
(current_datetime(),),
65-
TransactionRepositoryConflictException(""),
66-
TransactionRepositoryConflictException(""),
67-
TransactionRepositoryConflictException(""),
68-
TransactionRepositoryConflictException(""),
65+
ProgrammingException(""),
66+
ProgrammingException(""),
67+
ProgrammingException(""),
68+
ProgrammingException(""),
6969
],
7070
):
7171
await super().test_submit_reserving_raises()
@@ -76,9 +76,9 @@ async def test_submit_reserved_raises(self):
7676
"fetch_one",
7777
side_effect=[
7878
(current_datetime(),),
79-
TransactionRepositoryConflictException(""),
80-
TransactionRepositoryConflictException(""),
81-
TransactionRepositoryConflictException(""),
79+
ProgrammingException(""),
80+
ProgrammingException(""),
81+
ProgrammingException(""),
8282
],
8383
):
8484
await super().test_submit_reserved_raises()
@@ -89,12 +89,12 @@ async def test_submit_committing_raises(self):
8989
"fetch_one",
9090
side_effect=[
9191
(current_datetime(),),
92-
TransactionRepositoryConflictException(""),
93-
TransactionRepositoryConflictException(""),
94-
TransactionRepositoryConflictException(""),
95-
TransactionRepositoryConflictException(""),
96-
TransactionRepositoryConflictException(""),
97-
TransactionRepositoryConflictException(""),
92+
ProgrammingException(""),
93+
ProgrammingException(""),
94+
ProgrammingException(""),
95+
ProgrammingException(""),
96+
ProgrammingException(""),
97+
ProgrammingException(""),
9898
],
9999
):
100100
await super().test_submit_committing_raises()
@@ -105,9 +105,12 @@ async def test_submit_committed_raises(self):
105105
"fetch_one",
106106
side_effect=[
107107
(current_datetime(),),
108-
TransactionRepositoryConflictException(""),
109-
TransactionRepositoryConflictException(""),
110-
TransactionRepositoryConflictException(""),
108+
ProgrammingException(""),
109+
ProgrammingException(""),
110+
ProgrammingException(""),
111+
ProgrammingException(""),
112+
ProgrammingException(""),
113+
ProgrammingException(""),
111114
],
112115
):
113116
await super().test_submit_committed_raises()
@@ -118,12 +121,12 @@ async def test_submit_rejected_raises(self):
118121
"fetch_one",
119122
side_effect=[
120123
(current_datetime(),),
121-
TransactionRepositoryConflictException(""),
122-
TransactionRepositoryConflictException(""),
123-
TransactionRepositoryConflictException(""),
124-
TransactionRepositoryConflictException(""),
125-
TransactionRepositoryConflictException(""),
126-
TransactionRepositoryConflictException(""),
124+
ProgrammingException(""),
125+
ProgrammingException(""),
126+
ProgrammingException(""),
127+
ProgrammingException(""),
128+
ProgrammingException(""),
129+
ProgrammingException(""),
127130
],
128131
):
129132
await super().test_submit_rejected_raises()

packages/core/minos-microservice-common/minos/common/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from .database import (
1717
ComposedDatabaseOperation,
18+
ConnectionException,
1819
DatabaseClient,
1920
DatabaseClientBuilder,
2021
DatabaseClientException,
@@ -27,7 +28,7 @@
2728
IntegrityException,
2829
LockDatabaseOperationFactory,
2930
ManagementDatabaseOperationFactory,
30-
UnableToConnectException,
31+
ProgrammingException,
3132
)
3233
from .datetime import (
3334
NULL_DATETIME,

packages/core/minos-microservice-common/minos/common/database/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from .clients import (
2+
ConnectionException,
23
DatabaseClient,
34
DatabaseClientBuilder,
45
DatabaseClientException,
56
IntegrityException,
6-
UnableToConnectException,
7+
ProgrammingException,
78
)
89
from .locks import (
910
DatabaseLock,

packages/core/minos-microservice-common/minos/common/database/clients/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
DatabaseClientBuilder,
44
)
55
from .exceptions import (
6+
ConnectionException,
67
DatabaseClientException,
78
IntegrityException,
8-
UnableToConnectException,
9+
ProgrammingException,
910
)

packages/core/minos-microservice-common/minos/common/database/clients/abc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
DatabaseOperation,
3333
DatabaseOperationFactory,
3434
)
35+
from .exceptions import (
36+
ProgrammingException,
37+
)
3538

3639
if TYPE_CHECKING:
3740
from ..locks import (
@@ -137,7 +140,10 @@ async def fetch_one(self) -> Any:
137140
138141
:return: This method does not return anything.
139142
"""
140-
return await self.fetch_all().__anext__()
143+
try:
144+
return await self.fetch_all().__anext__()
145+
except StopAsyncIteration:
146+
raise ProgrammingException("There are not any value to be fetched.")
141147

142148
def fetch_all(self) -> AsyncIterator[Any]:
143149
"""Fetch all values with an asynchronous iterator.

packages/core/minos-microservice-common/minos/common/database/clients/exceptions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ class DatabaseClientException(MinosException):
77
"""Base exception for database client."""
88

99

10-
class UnableToConnectException(DatabaseClientException):
10+
class ConnectionException(DatabaseClientException):
1111
"""Exception to be raised when database client is not able to connect to the database."""
1212

1313

1414
class IntegrityException(DatabaseClientException):
1515
"""Exception to be raised when an integrity check is not satisfied."""
16+
17+
18+
class ProgrammingException(DatabaseClientException):
19+
"""Exception to be raised when an integrity check is not satisfied."""

packages/core/minos-microservice-common/minos/common/database/pools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
Pool,
2727
)
2828
from .clients import (
29+
ConnectionException,
2930
DatabaseClient,
3031
DatabaseClientBuilder,
31-
UnableToConnectException,
3232
)
3333
from .locks import (
3434
DatabaseLock,
@@ -66,7 +66,7 @@ async def _create_instance(self) -> Optional[DatabaseClient]:
6666

6767
try:
6868
await instance.setup()
69-
except UnableToConnectException:
69+
except ConnectionException:
7070
await sleep(0.1)
7171
return None
7272

0 commit comments

Comments
 (0)