File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,8 @@ def get_outer_type(field):
83
83
field .annotation
84
84
):
85
85
return field .annotation
86
+ elif not hasattr (field .annotation , "__args__" ):
87
+ return None
86
88
else :
87
89
return field .annotation .__args__ [0 ]
88
90
@@ -1953,6 +1955,9 @@ def schema_for_fields(cls):
1953
1955
1954
1956
for name , field in fields .items ():
1955
1957
_type = get_outer_type (field )
1958
+ if _type is None :
1959
+ continue
1960
+
1956
1961
if (
1957
1962
not isinstance (field , FieldInfo )
1958
1963
and hasattr (field , "metadata" )
Original file line number Diff line number Diff line change @@ -973,6 +973,30 @@ async def test_xfix_queries(m):
973
973
assert result .first_name == "Steve"
974
974
975
975
976
+ @py_test_mark_asyncio
977
+ async def test_model_with_dict ():
978
+ class EmbeddedJsonModelWithDict (EmbeddedJsonModel ):
979
+ dict : Dict
980
+
981
+ class ModelWithDict (JsonModel ):
982
+ embedded_model : EmbeddedJsonModelWithDict
983
+ info : Dict
984
+
985
+ await Migrator ().run ()
986
+ d = dict ()
987
+ inner_dict = dict ()
988
+ d ["foo" ] = "bar"
989
+ inner_dict ["bar" ] = "foo"
990
+ embedded_model = EmbeddedJsonModelWithDict (dict = inner_dict )
991
+ item = ModelWithDict (info = d , embedded_model = embedded_model )
992
+ await item .save ()
993
+
994
+ rematerialized = await ModelWithDict .find (ModelWithDict .pk == item .pk ).first ()
995
+ assert rematerialized .pk == item .pk
996
+ assert rematerialized .info ["foo" ] == "bar"
997
+ assert rematerialized .embedded_model .dict ["bar" ] == "foo"
998
+
999
+
976
1000
@py_test_mark_asyncio
977
1001
async def test_boolean ():
978
1002
class Example (JsonModel ):
You can’t perform that action at this time.
0 commit comments