full-stack-fastapi-template
full-stack-fastapi-template copied to clipboard
Update user fails when not provided a password
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.
#if update_data["password"]:
p = update_data.get("password")
if p is not None and str(p) != '':
Hey, I am experiencing the exact same issue.
Same here. This solves it for me:
if 'password' in update_data and update_data["password"]:
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: