full-stack-fastapi-template icon indicating copy to clipboard operation
full-stack-fastapi-template copied to clipboard

Bug: Updating user without updating password doesn't work

Open Hultner opened this issue 5 years ago • 3 comments

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.

Hultner avatar Oct 06 '20 11:10 Hultner

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.

Koschi13 avatar Oct 06 '20 12:10 Koschi13

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

Hultner avatar Oct 06 '20 13:10 Hultner

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.

romandueck avatar Dec 15 '20 22:12 romandueck