Skip to content

Commit 45e14e9

Browse files
author
Sergio García Prado
committed
Merge remote-tracking branch 'origin/0.8.0' into issue-51-implement-aiopg-saga-execution-repository
2 parents d1e687c + 28a6bf8 commit 45e14e9

File tree

14 files changed

+144
-61
lines changed

14 files changed

+144
-61
lines changed

packages/core/minos-microservice-aggregate/minos/aggregate/deltas/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def simplified_name(self) -> str:
6363
return self.name.rsplit(".", 1)[-1]
6464

6565
def __lt__(self, other: Any) -> bool:
66-
return isinstance(other, type(self)) and self.version < other.version
66+
return isinstance(other, type(self)) and (
67+
(self.name == other.name and self.version < other.version) or self.created_at < other.created_at
68+
)
6769

6870
def __getitem__(self, item: str) -> Any:
6971
try:

packages/core/minos-microservice-aggregate/tests/test_aggregate/test_deltas/test_models.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,17 @@ def test_simplified_name(self):
5555
self.assertEqual("Car", self.diff.simplified_name)
5656

5757
def test_total_ordering(self):
58-
observed = [
58+
values = [
5959
Delta.from_entity(Car(3, "blue", version=4)),
6060
Delta.from_entity(Car(3, "blue", version=1)),
6161
Delta.from_entity(Car(3, "blue", version=3)),
6262
Delta.from_entity(Car(3, "blue", version=2)),
63+
Delta.from_entity(Owner("foo", "bar", version=4, updated_at=current_datetime())),
64+
Delta.from_entity(Owner("foo", "bar", version=3, updated_at=current_datetime())),
6365
]
64-
observed.sort()
66+
observed = sorted(values)
6567

66-
expected = [
67-
Delta.from_entity(Car(3, "blue", version=1)),
68-
Delta.from_entity(Car(3, "blue", version=2)),
69-
Delta.from_entity(Car(3, "blue", version=3)),
70-
Delta.from_entity(Car(3, "blue", version=4)),
71-
]
68+
expected = [values[5], values[4], values[1], values[3], values[2], values[0]]
7269
self.assertEqual(expected, observed)
7370

7471
def test_from_entity(self):

packages/core/minos-microservice-common/minos/common/model/serializers/avro/data/decoder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
TYPE_CHECKING,
2525
Any,
2626
Optional,
27-
Type,
2827
TypeVar,
2928
Union,
3029
get_args,
@@ -251,7 +250,7 @@ def _build_uuid(data: Any, **kwargs) -> UUID:
251250
pass
252251
raise DataDecoderTypeException(UUID, data)
253252

254-
def _build_model(self, type_: Type[Model], data: Any, **kwargs) -> Any:
253+
def _build_model(self, type_: type[Model], data: Any, **kwargs) -> Any:
255254
if is_type_subclass(type_) and isinstance(data, type_):
256255
return data
257256
return self._build_model_type(ModelType.from_model(type_), data, **kwargs)
@@ -263,7 +262,7 @@ def _build_model_type(self, type_: ModelType, data: Any, **kwargs) -> Any:
263262
if (ans := type_.model_cls.decode_data(self, data, type_, **kwargs)) is not MissingSentinel:
264263
return ans
265264

266-
if isinstance(data, dict):
265+
if isinstance(data, Mapping):
267266
with suppress(Exception):
268267
decoded_data = {
269268
field_name: self._build(field_type, data[field_name], **kwargs)

packages/core/minos-microservice-common/tests/test_common/test_model/test_serializers/test_avro/test_data/test_decoder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ def test_model_with_inheritance(self):
303303
observed = decoder.build(value)
304304
self.assertEqual(value, observed)
305305

306+
# noinspection PyUnusedLocal,PyPep8Naming
307+
def test_model_with_model(self):
308+
Foo = ModelType.build("Foo", one=int)
309+
Bar = ModelType.build("Bar", one=int, two=str)
310+
311+
self.assertEqual(Foo(1234), AvroDataDecoder(Foo).build(Bar(1234, "5678")))
312+
self.assertEqual(Foo(1234), AvroDataDecoder(Union[Foo, Bar]).build(Bar(1234, "5678")))
313+
self.assertEqual(Bar(1234, "5678"), AvroDataDecoder(Union[Bar, Foo]).build(Bar(1234, "5678")))
314+
306315
def test_model_from_dict(self):
307316
decoder = AvroDataDecoder(User)
308317
value = User(1234)

packages/core/minos-microservice-saga/minos/saga/definitions/operations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Operation module."""
2+
13
from __future__ import (
24
annotations,
35
)
@@ -31,7 +33,7 @@
3133

3234

3335
class SagaOperationDecorator(Generic[T]):
34-
""" "TODO"""
36+
"""Saga Operation Decorator class."""
3537

3638
def __init__(self, attr_name: str = None, step_meta: SagaStepDecoratorMeta = None, *args, **kwargs):
3739
if attr_name is None:

packages/core/minos-microservice-saga/minos/saga/definitions/saga.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Saga definitions module."""
2+
13
from __future__ import (
24
annotations,
35
)
@@ -50,13 +52,13 @@
5052

5153
@runtime_checkable
5254
class SagaDecoratorWrapper(Protocol):
53-
"""TODO"""
55+
"""Saga Decorator Wrapper class."""
5456

5557
meta: SagaDecoratorMeta
5658

5759

5860
class SagaDecoratorMeta:
59-
"""TODO"""
61+
"""Saga Decorator Meta class."""
6062

6163
_inner: type
6264
_definition: Saga
@@ -67,7 +69,10 @@ def __init__(self, func: type, saga: Saga):
6769

6870
@cached_property
6971
def definition(self) -> Saga:
70-
"""TODO"""
72+
"""Get the saga definition.
73+
74+
:return: A ``Saga`` instance.
75+
"""
7176
steps = getmembers(self._inner, predicate=lambda x: isinstance(x, SagaStepDecoratorWrapper))
7277
steps = list(map(lambda member: member[1].meta.definition, steps))
7378
for step in steps:
@@ -113,6 +118,11 @@ def __init__(
113118
self.committed = True
114119

115120
def __call__(self, type_: TP) -> Union[TP, SagaDecoratorWrapper]:
121+
"""Decorate the given type.
122+
123+
:param type_: The type to be decorated.
124+
:return: The decorated type.
125+
"""
116126
type_.meta = SagaDecoratorMeta(type_, self)
117127
return type_
118128

@@ -182,11 +192,11 @@ def remote_step(
182192
return self.add_step(step, RemoteSagaStep)
183193

184194
def add_step(self, step: Optional[Union[SagaOperation, T]], step_cls: type[T] = SagaStep) -> T:
185-
"""TODO
195+
"""Add a new step.
186196
187-
:param step: TODO
188-
:param step_cls: TODO
189-
:return: TODO
197+
:param step: The step to be added.
198+
:param step_cls: The step class (for validation purposes).
199+
:return: The added step.
190200
"""
191201
if self.committed:
192202
raise AlreadyCommittedException("It is not possible to add more steps to an already committed saga.")

packages/core/minos-microservice-saga/minos/saga/definitions/steps/abc.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Base Step Definitions module."""
2+
13
from __future__ import (
24
annotations,
35
)
@@ -45,13 +47,13 @@
4547

4648
@runtime_checkable
4749
class SagaStepDecoratorWrapper(Protocol):
48-
"""TODO"""
50+
"""Saga Step Decorator Wrapper class."""
4951

5052
meta: SagaStepDecoratorMeta
5153

5254

5355
class SagaStepDecoratorMeta:
54-
"""TODO"""
56+
"""Saga Step Decorator Meta class."""
5557

5658
_inner: Any
5759
_definition: SagaStep
@@ -63,7 +65,10 @@ def __init__(self, inner: Any, definition: SagaStep):
6365
@property
6466
@abstractmethod
6567
def definition(self) -> SagaStep:
66-
"""TODO"""
68+
"""Get the step definition.
69+
70+
:return: A ``SagaStep`` instance.
71+
"""
6772

6873

6974
class SagaStep(ABC):
@@ -104,7 +109,11 @@ def _from_raw(cls, raw: dict[str, Any]) -> SagaStep:
104109

105110
@abstractmethod
106111
def __call__(self, func: Callable) -> SagaStepDecoratorWrapper:
107-
"""TODO"""
112+
"""Decorate the given function.
113+
114+
:param func: The function to be decorated.
115+
:return: The decorated function.
116+
"""
108117

109118
def conditional_step(self, *args, **kwargs) -> ConditionalSagaStep:
110119
"""Create a new conditional step in the ``Saga``.

packages/core/minos-microservice-saga/minos/saga/definitions/steps/conditional.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Conditional Step Definitions module."""
2+
13
from __future__ import (
24
annotations,
35
)
@@ -55,19 +57,22 @@
5557

5658
@runtime_checkable
5759
class ConditionalSagaStepDecoratorWrapper(SagaStepDecoratorWrapper, Protocol):
58-
"""TODO"""
60+
"""Conditional Saga Step Decorator Wrapper class."""
5961

6062
meta: ConditionalSagaStepDecoratorMeta
6163

6264

6365
class ConditionalSagaStepDecoratorMeta(SagaStepDecoratorMeta):
64-
"""TODO"""
66+
"""Conditional Saga Step Decorator Meta class."""
6567

6668
_definition: ConditionalSagaStep
6769

6870
@cached_property
6971
def definition(self):
70-
"""TODO"""
72+
"""Get the step definition.
73+
74+
:return: A ``SagaStep`` instance.
75+
"""
7176
if_then_alternatives = getmembers(
7277
self._inner,
7378
predicate=(
@@ -140,6 +145,11 @@ def _from_raw(cls, raw: dict[str, Any], **kwargs) -> ConditionalSagaStep:
140145
return cls(**current)
141146

142147
def __call__(self, type_: TP) -> Union[TP, ConditionalSagaStepDecoratorWrapper]:
148+
"""Decorate the given type.
149+
150+
:param type_: The type to be decorated.
151+
:return: The decorated type.
152+
"""
143153
meta = ConditionalSagaStepDecoratorMeta(type_, self)
144154
type_.meta = meta
145155
return type_
@@ -226,22 +236,25 @@ def __iter__(self) -> Iterable:
226236

227237
@runtime_checkable
228238
class IfThenAlternativeDecoratorWrapper(Protocol):
229-
"""TODO"""
239+
"""If Then Alternative Decorator Wrapper class."""
230240

231241
meta: IfThenAlternativeDecoratorMeta
232242
__call__: ConditionCallback
233243

234244

235245
class IfThenAlternativeDecoratorMeta:
236-
"""TODO"""
246+
"""If Then Alternative Decorator Meta class."""
237247

238248
def __init__(self, inner: ConditionCallback, alternative: IfThenAlternative):
239249
self._inner = inner
240250
self._alternative = alternative
241251

242252
@cached_property
243253
def alternative(self) -> IfThenAlternative:
244-
"""TODO"""
254+
"""Get the if-then alternative.
255+
256+
:return: A ``IfThenAlternative`` instance.
257+
"""
245258
self._alternative.condition = SagaOperation(self._inner)
246259
return self._alternative
247260

@@ -305,6 +318,7 @@ def raw(self) -> dict[str, Any]:
305318
"""
306319

307320
return {
321+
"order": self.order,
308322
"condition": self.condition.raw,
309323
"saga": self.saga.raw,
310324
}
@@ -324,22 +338,25 @@ def __iter__(self):
324338

325339
@runtime_checkable
326340
class ElseThenAlternativeDecoratorWrapper(Protocol):
327-
"""TODO"""
341+
"""Else Then Alternative Decorator Wrapper class."""
328342

329343
meta: ElseThenAlternativeDecoratorMeta
330344
__call__: Callable
331345

332346

333347
class ElseThenAlternativeDecoratorMeta:
334-
"""TODO"""
348+
"""Else Then Alternative Decorator Meta class."""
335349

336350
def __init__(self, inner: Callable, alternative: ElseThenAlternative):
337351
self._inner = inner
338352
self._alternative = alternative
339353

340354
@cached_property
341355
def alternative(self) -> ElseThenAlternative:
342-
"""TODO"""
356+
"""Get the else-then alternative.
357+
358+
:return: A ``ElseThenAlternative`` instance.
359+
"""
343360
return self._alternative
344361

345362

packages/core/minos-microservice-saga/minos/saga/definitions/steps/local.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Local Step Definitions module."""
2+
13
from __future__ import (
24
annotations,
35
)
@@ -49,15 +51,15 @@
4951

5052
@runtime_checkable
5153
class LocalSagaStepDecoratorWrapper(SagaStepDecoratorWrapper, Protocol):
52-
"""TODO"""
54+
"""Local Saga Step Decorator Wrapper class."""
5355

5456
meta: LocalSagaStepDecoratorMeta
5557
on_failure: type[SagaOperationDecorator[LocalCallback]]
5658
__call__: LocalCallback
5759

5860

5961
class LocalSagaStepDecoratorMeta(SagaStepDecoratorMeta):
60-
"""TODO"""
62+
"""Local Saga Step Decorator Meta class."""
6163

6264
_definition: LocalSagaStep
6365
_on_failure: Optional[LocalCallback]
@@ -68,17 +70,23 @@ def __init__(self, *args, **kwargs):
6870

6971
@cached_property
7072
def definition(self):
71-
"""TODO"""
73+
"""Get the step definition.
74+
75+
:return: A ``SagaStep`` instance.
76+
"""
7277
self._definition.on_execute(self._inner)
7378
if self._on_failure is not None:
7479
self._definition.on_failure(self._on_failure)
7580
return self._definition
7681

7782
@cached_property
7883
def on_failure(self) -> SagaOperationDecorator:
79-
"""TODO"""
84+
"""Get the on failure decorator.
85+
86+
:return: A ``SagaOperationDecorator`` type.
87+
"""
8088
# noinspection PyTypeChecker
81-
return partial(SagaOperationDecorator, step_meta=self, attr_name="_on_failure")
89+
return partial(SagaOperationDecorator[LocalCallback], step_meta=self, attr_name="_on_failure")
8290

8391

8492
class LocalSagaStep(SagaStep):
@@ -109,6 +117,11 @@ def _from_raw(cls, raw: dict[str, Any]) -> LocalSagaStep:
109117
return cls(**raw)
110118

111119
def __call__(self, func: LocalCallback) -> LocalSagaStepDecoratorWrapper:
120+
"""Decorate the given function.
121+
122+
:param func: The function to be decorated.
123+
:return: The decorated function.
124+
"""
112125
meta = LocalSagaStepDecoratorMeta(func, self)
113126
func.meta = meta
114127
func.on_failure = meta.on_failure
@@ -121,7 +134,7 @@ def on_execute(
121134
122135
:param operation: The callback function to be called.
123136
:param parameters: A mapping of named parameters to be passed to the callback.
124-
:param kwargs: A set of named arguments to be passed to the callback. ``parameters`` has order if it is not
137+
:param kwargs: A set of named arguments to be passed to the callback. ``parameters`` has priority if it is not
125138
``None``.
126139
:return: A ``self`` reference.
127140
"""
@@ -142,7 +155,7 @@ def on_failure(
142155
143156
:param operation: The callback function to be called.
144157
:param parameters: A mapping of named parameters to be passed to the callback.
145-
:param kwargs: A set of named arguments to be passed to the callback. ``parameters`` has order if it is not
158+
:param kwargs: A set of named arguments to be passed to the callback. ``parameters`` has priority if it is not
146159
``None``.
147160
:return: A ``self`` reference.
148161
"""

0 commit comments

Comments
 (0)