We Are Going To Discuss About pydantic.error_wrappers.ValidationError: 1 validation error for B. So lets Start this Python Article.
pydantic.error_wrappers.ValidationError: 1 validation error for B
- How to solve pydantic.error_wrappers.ValidationError: 1 validation error for B
Oh, it was so simple… instead of using a
dict
type, just use the modelA
, which already matches the subobject.from pydantic import BaseModel, Field class A(BaseModel): a: str = Field(None, alias="А") class B(BaseModel): b: A = Field(None, alias="Б") j = { "Б": { "А": "Значение" } } obj = B.parse_obj(j) print(obj.json())
- pydantic.error_wrappers.ValidationError: 1 validation error for B
Oh, it was so simple… instead of using a
dict
type, just use the modelA
, which already matches the subobject.from pydantic import BaseModel, Field class A(BaseModel): a: str = Field(None, alias="А") class B(BaseModel): b: A = Field(None, alias="Б") j = { "Б": { "А": "Значение" } } obj = B.parse_obj(j) print(obj.json())
Solution 1
Oh, it was so simple… instead of using a dict
type, just use the model A
, which already matches the subobject.
from pydantic import BaseModel, Field
class A(BaseModel):
a: str = Field(None, alias="А")
class B(BaseModel):
b: A = Field(None, alias="Б")
j = {
"Б": {
"А": "Значение"
}
}
obj = B.parse_obj(j)
print(obj.json())
Original Author edited Apr 8 at 16:42 Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.