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

User update CRUD method only supports updates with password field

Open rkrn opened this issue 5 years ago • 1 comments

This line doesn't seem to be doing its intended purpose.

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

With this, if the password key is not set, then it will raise a KeyError, so the only viable code path is within the if statement. At this moment none of the demo update endpoints will run into this error as they happen to only pass UserUpdate objects to this method.

However it seems the intended purpose of the update method is to support any general update to the User database object, including updates to any single field besides the password field with a dict, e.g. obj_in can be {"full_name": "New name"}:

https://github.com/tiangolo/full-stack-fastapi-postgresql/blob/490c554e23343eec0736b06e59b2108fdd057fdc/%7B%7Bcookiecutter.project_slug%7D%7D/backend/app/app/crud/base.py#L50-L56

A simple change to:

if update_data.get("password"):
    ...

will remain compatible while achieving the intended purpose.

rkrn avatar Nov 18 '20 13:11 rkrn

There is already a MR #346 to fix this.

thomas-chauvet avatar Mar 12 '21 08:03 thomas-chauvet