From f4e8a87b1cbdb6d942ad237342664d914ecf8730 Mon Sep 17 00:00:00 2001 From: FrankApiyo Date: Wed, 15 Sep 2021 15:22:23 +0300 Subject: [PATCH] Ensure that user_profile is serialized before caching --- onadata/apps/api/viewsets/connect_viewset.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/onadata/apps/api/viewsets/connect_viewset.py b/onadata/apps/api/viewsets/connect_viewset.py index aae99b48e7..1f4cc333a2 100644 --- a/onadata/apps/api/viewsets/connect_viewset.py +++ b/onadata/apps/api/viewsets/connect_viewset.py @@ -3,6 +3,7 @@ from django.utils.decorators import classonlymethod from django.utils.translation import ugettext as _ from django.views.decorators.cache import never_cache +from django.contrib.auth.models import User from rest_framework import status, viewsets from rest_framework.authtoken.models import Token from rest_framework.decorators import action @@ -14,6 +15,8 @@ from onadata.apps.api.models.odk_token import ODKToken from onadata.apps.api.models.temp_token import TempToken from onadata.apps.api.permissions import ConnectViewsetPermissions +from onadata.apps.api.viewsets.user_profile_viewset import \ + serializer_from_settings from onadata.apps.main.models.user_profile import UserProfile from onadata.libs.mixins.authenticate_header_mixin import \ AuthenticateHeaderMixin @@ -51,9 +54,12 @@ def user_profile_w_token_response(request, status): with use_master: user_profile, _ = UserProfile.objects.get_or_create( user=request.user) + serializer = serializer_from_settings()( + user_profile, + context={'request': request}) cache.set( f'{USER_PROFILE_PREFIX}{request.user.username}', - user_profile) + serializer.data) serializer = UserProfileWithTokenSerializer( instance=user_profile, context={"request": request})