Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
pydantic nested model response

I want to pass nested models into the response. I am trying by making object of 1 model then storing the related values to it, making object of 2nd model and storing related values to it and at the last trying to store thoes 2 model in the response model. Can you guys please help me out. Thank you

Models

class SetImageSetInput(BaseModel):
  profileId: str
  
  class Config:
    orm_mode = True



class ValidateFaceAlignmentInput(BaseModel):
  currentFrame: str
  
  class Config:
    orm_mode = True

class outputResponse(BaseModel):
    response1: ValidateFaceAlignmentInput
    response2: SetImageSetInput


SetImageSetInput.profileId="pic1"
ValidateFaceAlignmentInput.currentFrame="1"
outputResponse.response1 = SetImageSetInput
outputResponse.response2 = ValidateFaceAlignmentInput

return SetImageSetInput

But I am getting error while executing this api

pydantic.error_wrappers.ValidationError: 1 validation error for outputResponse
response -> response1
  field required (type=value_error.missing)
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You just have to create instances of the corresponding classes and pass those to your reponse model object in the constructor. In code, it should read like

response = outputResponse(
    response1= ValidateFaceAlignmentInput(currentFrame ='1'), 
    response2=SetImageSetInput(profileId ='pic1'), 
)
return response
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda