-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Closed
Labels
Description
Example code:
class BaseMessage(BaseModel):
id_trx: float
date: str
id_cost: float
n_id_issuer: float
@classmethod
def get_validators(cls):
# yield dict_validator
yield cls.validate
@classmethod
def validate(cls, value):
if isinstance(value, cls):
return value
else:
return cls(**dict_validator(value))
class SubMessageOne(BaseMessage):
a: str
b: str
class SubMessageTwo(BaseMessage):
c: str
@app.post("/test")
async def test(m: BaseMessage):
return isinstance(m, SubMessageOne)
POST JSON example:
{
"id_trx": 5,
"date": "20190101",
"id_cost": 250.7,
"n_id_issuer": 45,
"a" : "a uno",
"b" : "b uno"
}
It returns false from test method, I cannot access to SubMessageOne attributes a and b.
I would like to know if exits a workaround to solve this issue or it isn't supported.
Best Regards,
Valentina.