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

114
Views
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 answers
Answer question

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 Report
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!