r/FastAPI • u/Remarkable-Effort-93 • Oct 17 '25
Question I need help with this!
So I'm working on an API that receives an object representing comercial products as requests, the requests loos something like this:
{
common_field_1: value,
common_field_2: value,
common_field_3: value,
product_name: product_name,
product_id: product_id,
product_sub_id: product_sub_id,
product: {
field_1: value,
field_2: value
}
}
So, every product has common fields, identity fields, and a product object with its properties.
This escenario makes it difficult to use discrimination directly from the request via Pydantic because not product nor sub_product are unique values, but the combination, sort of a composed key, but from what I've read so far, Pydantic can only handle discrimation via 1 unique field or a hierchy discrimination that handles 1 field then a second one but the second one most be part of a nested object from the first field.
I hope I explained myself and the situation... Any ideas on how to solve this would be appreciated, thank you!
View all comments
Show parent comment
1
u/Remarkable-Effort-93 Oct 17 '25
Thanks! I'm not that good with Documentation but I'll try to figure it out from here, much appreciated!