Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

KeyError: 'profile' and KeyError: 'user' #20

Open
leros opened this issue Dec 6, 2018 · 2 comments
Open

KeyError: 'profile' and KeyError: 'user' #20

leros opened this issue Dec 6, 2018 · 2 comments

Comments

@leros
Copy link

leros commented Dec 6, 2018

I am running the app in dev model. I tried to add a new article for a new user and got KeyError: 'profile' which was due to a problem of this code:

  .../flask-realworld-example-app/conduit/profile/serializers.py", line 18, in make_user
    return data['profile']`

Also, I got another key error when trying to update user profile:

  File "/Users/demo/learn-fullstack/flask-realworld-example-app/conduit/user/serializers.py", line 21, in make_user
    data = data['user']
KeyError: 'user'
@przor3n
Copy link

przor3n commented Nov 10, 2019

so, if you are still looking for solution, then you have to comment out @pre_load decorator in
profile's serializer.py. this will give you and error, that is solved by adding author=None as an argument to article view function make_article. this makes adding articles possible, user is set.

you can remove the @pre_load decorator from user/serializer.py, this will show you an error 422. i'm still struggling with it.

@przor3n
Copy link

przor3n commented Nov 11, 2019

serializers for user and profile assume that every time frontend sends {'user': #payload } or {'profile': #payload }, but update and create article send only dict with payload keyvals.
so solution is to check if the user and profile key is in data, in functions decorated with pre_load (do something like this: return data.get('profile', data))

still, add that author=None to make_article.

for updating, you also need to allow for password to be empty in UserSchema.
( password = fields.Str(load_only=True, allow_none=True) )
I think it need new schema for updating user profile.

rajgoesout added a commit to rajgoesout/CI_CD_server_flask that referenced this issue Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants