0

Today I discovered something weird, and I need an explanation please.

This is my current pipeline of django-social-auth

SOCIAL_AUTH_PIPELINE = (
    'social_auth.backends.pipeline.social.social_auth_user',
    'social_auth.backends.pipeline.associate.associate_by_email',
    'social_auth.backends.pipeline.user.get_username',
    'social_auth.backends.pipeline.user.create_user',
    'social_auth.backends.pipeline.social.associate_user',
    'apps.main.pipeline.load_user_data',
    'social_auth.backends.pipeline.social.load_extra_data',
    'social_auth.backends.pipeline.user.update_user_details'
)

As you can see, I have a partial pipeline, the load_user_data method, where the problems resides :

def load_user_data(request, user, *args, **kwargs):
    x = User.objects.get(id=user.id)
    x.fid = 123
    x.save() # <-- Nothing changes in db . I even used force_update attribute.
    
    user.fid = 123
    user.save() # <-- it works.

So, I can't understand why x.save() didn't work, I struggled with this problem many hours.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Daniel Flores
  • 770
  • 3
  • 12
  • 31

1 Answers1

0
def load_user_data(request, user, *args, **kwargs):
    x = User.objects.get_or_create(id=user.id) # this is looking for specyfic User, if nothing found it will create one. In your solution x wasnt User instance, so you cant save it.
    x.fid = 123
    x.save() # <-- Nothing changes in db . I even used force_update attribute.

    user.fid = 123 # User instance.
    user.save() # <-- it works.
Piotr Kowalczuk
  • 400
  • 5
  • 19