You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
in MarkdownJsonDictParser, the parse function use response.parsed = dict(self.pydantic_class(**response.parsed)) to transfer pydantic model to dict, it's not good for a nested data.
you should use response.parsed = self.pydantic_class(**response.parsed).model_dump() instead
this is the source code
frompydanticimportBaseModel,FieldimportjsonclassInsideSchema(BaseModel):
key:str=Field("value", description="key")
classNestedStructure(BaseModel):
object: InsideSchema=Field(default_factory=InsideSchema, description="object")
if__name__=="__main__":
data=NestedStructure()
print(data.model_dump()) # {'object': {'key': 'value'}}print(dict(data)) # {'object': InsideSchema(key='value')}try:
json.dumps(dict(data))
exceptExceptionase:
print(e) # Object of type InsideSchema is not JSON serializable
the result will show that dict(*) won't parse complicated data, inside the 'object' is a pydantic data type InsideSchema(key='value'), not a dict {'key': 'value'}.
it will raise error when you dump the it.
The text was updated successfully, but these errors were encountered:
Describe the bug
in
MarkdownJsonDictParser
, theparse
function useresponse.parsed = dict(self.pydantic_class(**response.parsed))
to transfer pydantic model to dict, it's not good for a nested data.you should use
response.parsed = self.pydantic_class(**response.parsed).model_dump()
insteadthis is the source code
I will show you an example
To Reproduce
this is an example why don't do it.
the result will show that
dict(*)
won't parse complicated data, inside the 'object' is a pydantic data typeInsideSchema(key='value')
, not a dict{'key': 'value'}
.it will raise error when you dump the it.
The text was updated successfully, but these errors were encountered: