Model with custom root type fails if in a nested model #2480
-
I'm not sure if this is a bug or not but it feels like a bug to me. Here is the example where the last line causes a from pydantic import BaseModel
from typing import Union, List
class A(BaseModel):
name: str
class B(BaseModel):
pipeline: List["Component"]
class Component(BaseModel):
__root__: Union[A, B]
B.update_forward_refs(Component=Component)
Component.parse_obj({"name": "John Doe"}) # passes
Component.parse_obj({"pipeline": [{"__root__": {"name": "John Doe"}}]}) # passes
Component.parse_obj({"pipeline": [{"name": "John Doe"}]}) # fails |
Beta Was this translation helpful? Give feedback.
Answered by
PrettyWood
Mar 5, 2021
Replies: 2 comments 1 reply
-
Actually now that I look at it, it sorta makes sense. I still wonder how to achieve my goal here in the best and most simple way. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I thought I fixed this in |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
NixBiks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I thought I fixed this in
v1.8
🤔 Which version do you use please?