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

Update user fails when not provided a password

Open chris-allnutt opened this issue 5 years ago • 3 comments

Logged into the vue UI and attempted to change the Full Name value resulted in a key error for the following line

Error Output

backend_1       |   File "./app/crud/crud_user.py", line 34, in update
backend_1       |     if update_data["password"]:
backend_1       | KeyError: 'password'

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

The frontend sends the following as the payload

{full_name: "Chris Allnutt", email: "chris@some_domain_here.com"}

I'd be happy to open a PR if someone could provide direction on the fix, as far as I can tell exclude_unset combined with the check of the password is what's causing the issue.

I also think it makes sense to get rid of the Union[UserUpdate, Dict[str, Any] and just use UserUpdate for consistency.

My fix would be to change the check to be if "password" in update_data.keys(): but I'm open to other ideas as well.

chris-allnutt avatar Apr 25 '20 17:04 chris-allnutt

    #if update_data["password"]:
    p = update_data.get("password")
    if p is not None and  str(p) != '':

fancar avatar Apr 28 '20 10:04 fancar

Hey, I am experiencing the exact same issue.

SeanPedersen avatar Dec 14 '20 12:12 SeanPedersen

Same here. This solves it for me:

if 'password' in update_data and update_data["password"]:

bechtold avatar Jul 22 '21 12:07 bechtold

Thanks! This was solved in some PRs recently. If you still have errors after trying with the new code, please let me know. :nerd_face: :coffee:

tiangolo avatar Mar 12 '24 16:03 tiangolo