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

115
Vistas
Problem: responseModel being ignored. FastApi (python 3.8)

I am using FastApi and My responseModel is being ignored. I am attempting to NOT return the password field in the response. Why does FastApi ignore my responsemodel definition?

Here is my api post method:

@app.post("/users")
def create_users(user: schemas.UserCreate, db: Session = Depends(get_db), response_model=schemas.UserOut):
    new_user = models.User(**user.dict())
    print(new_user)
    db.add(new_user)
    db.commit()
    db.refresh(new_user)
    return new_user

here is the postman return I should not see the password field:

{
    "password": "sdmfsladfj",
    "email": "hon99@gmail.com",
    "created_at": "2022-02-05T00:17:11.010020-06:00",
    "id": 10
}

Here is my responseModel definition in my schemas.py file:

class UserOut(BaseModel):
    id: int
    email: EmailStr
    created_at: datetime

    class Config:
        orm_mode = True




 anyio==3.5.0
    asgiref==3.5.0
    click==8.0.3
    dnspython==2.2.0
    email-validator==1.1.3
    emailvalidator==0.3
    fastapi==0.73.0
    greenlet==1.1.2
    h11==0.13.0
    idna==3.3
    psycopg2-binary==2.9.3
    pydantic==1.9.0
    sniffio==1.2.0
    SQLAlchemy==1.4.31
    sqlalchemy2-stubs==0.0.2a19
    sqlmodel==0.0.6
    starlette==0.17.1
    typing_extensions==4.0.1
    utcnow==0.3.0
    uvicorn==0.17.1
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

response_model is an argument to the view decorator (since it's metadata about the view itself), not to the view function (which takes arguments that are necessary for how to process the view):

@app.post("/users", response_model=schemas.UserOut):
async def ...
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