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.