Skip to content

Commit 8c34054

Browse files
author
Sergio García Prado
committed
Merge remote-tracking branch 'origin/0.7.1' into 0.7.1
2 parents 140304b + 48eab5e commit 8c34054

File tree

2 files changed

+11
-3
lines changed
  • packages/core/minos-microservice-common
    • minos/common/model/serializers/avro/data
    • tests/test_common/test_model/test_serializers/test_avro/test_data

2 files changed

+11
-3
lines changed

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,
@@ -241,7 +240,7 @@ def _build_uuid(data: Any, **kwargs) -> UUID:
241240
pass
242241
raise DataDecoderTypeException(UUID, data)
243242

244-
def _build_model(self, type_: Type[Model], data: Any, **kwargs) -> Any:
243+
def _build_model(self, type_: type[Model], data: Any, **kwargs) -> Any:
245244
if is_type_subclass(type_) and isinstance(data, type_):
246245
return data
247246
return self._build_model_type(ModelType.from_model(type_), data, **kwargs)
@@ -254,7 +253,7 @@ def _build_model_type(self, type_: ModelType, data: Any, **kwargs) -> Any:
254253
if (ans := type_.model_cls.decode_data(self, data, type_, **kwargs)) is not MissingSentinel:
255254
return ans
256255

257-
if isinstance(data, dict):
256+
if isinstance(data, Mapping):
258257
with suppress(Exception):
259258
decoded_data = {
260259
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)

0 commit comments

Comments
 (0)