Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Pydantic Not Deserializing Sqlalchemy when I query using with entities

I use this part of code to get data from the db

class OrmModel(BaseModel):
    class Config:
        orm_mode = True

class PruebaVozFila(OrmModel):
    id:int 
    id_origen:int 
    id_destino:int
    hora_programada:str
    hora_ejecutada:str 
    exitoso:bool 
    estado:str 
@router.get("/pruebas-voz",response_model=PruebaVozFila)
def obtener_pruebas_voz(
    *,
    db: Session = Depends(deps.get_db),
    current_user: models.User = Depends(deps.get_current_active_user),
    search:Search = Depends(Search)
    ) -> Any:

    temporal_query = db.query(PruebaVoz).filter().with_entities(
        
    PruebaVoz.id,
    PruebaVoz.id_origen,
    PruebaVoz.id_destino,
    PruebaVoz.hora_programada,
    PruebaVoz.hora_ejecutada,
    PruebaVoz.exitoso,
    PruebaVoz.estado,

    ).first()

    return  jsonable_encoder(temporal_query)

So when I query without using 'with_entities' it works but if I add it,it throws the following error enter image description here

It seems that Pydantic is unable to find the columns or its names inside the temporal_query I print the query as SQL and gives me this With "with_entities"

SELECT pruebavoz.id AS pruebavoz_id, pruebavoz.id_origen AS pruebavoz_id_origen, pruebavoz.id_destino AS pruebavoz_id_destino, pruebavoz.hora_programada AS pruebavoz_hora_programada, pruebavoz.hora_ejecutada AS pruebavoz_hora_ejecutada, pruebavoz.exitoso AS pruebavoz_exitoso, pruebavoz.estado AS pruebavoz_estado 

Without "with_entities"

SELECT pruebavoz.id AS pruebavoz_id, pruebavoz.id_origen AS pruebavoz_id_origen, pruebavoz.id_destino AS pruebavoz_id_destino, pruebavoz.hora_programada AS pruebavoz_hora_programada, pruebavoz.hora_ejecutada AS pruebavoz_hora_ejecutada, pruebavoz.exitoso AS pruebavoz_exitoso, pruebavoz.estado AS pruebavoz_estado, pruebavoz.usuario_ingreso AS pruebavoz_usuario_ingreso, pruebavoz.creado AS pruebavoz_creado, pruebavoz.actualizado AS pruebavoz_actualizado

as you see in the actual query the parameters are the same.What do you think is happening.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!