File tree Expand file tree Collapse file tree 3 files changed +3
-0
lines changed Expand file tree Collapse file tree 3 files changed +3
-0
lines changed Original file line number Diff line number Diff line change
1
+ fix parsing of custom root models
Original file line number Diff line number Diff line change @@ -508,6 +508,7 @@ def json(
508
508
def _enforce_dict_if_root (cls , obj : Any ) -> Any :
509
509
if cls .__custom_root_type__ and (
510
510
not (isinstance (obj , dict ) and obj .keys () == {ROOT_KEY })
511
+ and not (isinstance (obj , BaseModel ) and obj .__fields__ .keys () == {ROOT_KEY })
511
512
or cls .__fields__ [ROOT_KEY ].shape in MAPPING_LIKE_SHAPES
512
513
):
513
514
return {ROOT_KEY : obj }
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ class MyModel(BaseModel):
46
46
m = MyModel .parse_obj ('a' )
47
47
assert m .dict () == {'__root__' : 'a' }
48
48
assert m .__root__ == 'a'
49
+ assert MyModel .parse_obj (m ) == m
49
50
50
51
51
52
def test_parse_root_list ():
You can’t perform that action at this time.
0 commit comments