fastapi / full-stack-fastapi-template

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.
MIT License
27.33k stars 4.88k forks source link

Bug: Updating user without updating password doesn't work #285

Open Hultner opened 4 years ago

Hultner commented 4 years ago

If you try to update a user via the admin interface without changing the users password you will get a 500 error and a key-error in the logs, this is due to accessing the missing property directly while checking.

Error originates here: https://github.com/tiangolo/full-stack-fastapi-postgresql/blob/490c554e23343eec0736b06e59b2108fdd057fdc/%7B%7Bcookiecutter.project_slug%7D%7D/backend/app/app/crud/crud_user.py#L34

In my own copy I've solved this by changing it to:

 if update_data.get("password", default=False): 

This has the additional benefit of being more explicit about the missing case by using dict.get with a explicit default value.

Koschi13 commented 4 years ago

Hey, this is a duplicate of https://github.com/tiangolo/full-stack-fastapi-postgresql/issues/166 maybe which also has a PR already https://github.com/tiangolo/full-stack-fastapi-postgresql/pull/168

I think you should join the conversation over there.

Hultner commented 4 years ago

After looking around there seems to be multiple PR's and issues about this.

romandueck commented 3 years ago

Hey, one more Thing: if update_data.get("password", default=False): It doesn't work so for me in frontend app because of this error: TypeError: get() takes no keyword arguments.

if update_data.get("password", False): works perfect.