diff --git a/aredis_om/model/model.py b/aredis_om/model/model.py index 5d0a9dea..f6888a4f 100644 --- a/aredis_om/model/model.py +++ b/aredis_om/model/model.py @@ -83,6 +83,8 @@ def get_outer_type(field): field.annotation ): return field.annotation + elif not hasattr(field.annotation, "__args__"): + return None else: return field.annotation.__args__[0] @@ -1953,6 +1955,9 @@ def schema_for_fields(cls): for name, field in fields.items(): _type = get_outer_type(field) + if _type is None: + continue + if ( not isinstance(field, FieldInfo) and hasattr(field, "metadata") diff --git a/tests/test_json_model.py b/tests/test_json_model.py index 2906b745..6e5cead4 100644 --- a/tests/test_json_model.py +++ b/tests/test_json_model.py @@ -973,6 +973,30 @@ async def test_xfix_queries(m): assert result.first_name == "Steve" +@py_test_mark_asyncio +async def test_model_with_dict(): + class EmbeddedJsonModelWithDict(EmbeddedJsonModel): + dict: Dict + + class ModelWithDict(JsonModel): + embedded_model: EmbeddedJsonModelWithDict + info: Dict + + await Migrator().run() + d = dict() + inner_dict = dict() + d["foo"] = "bar" + inner_dict["bar"] = "foo" + embedded_model = EmbeddedJsonModelWithDict(dict=inner_dict) + item = ModelWithDict(info=d, embedded_model=embedded_model) + await item.save() + + rematerialized = await ModelWithDict.find(ModelWithDict.pk == item.pk).first() + assert rematerialized.pk == item.pk + assert rematerialized.info["foo"] == "bar" + assert rematerialized.embedded_model.dict["bar"] == "foo" + + @py_test_mark_asyncio async def test_boolean(): class Example(JsonModel):