Skip to content

Commit

Permalink
Ensure that user_profile is serialized before caching
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Sep 15, 2021
1 parent 7236e71 commit f4e8a87
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion onadata/apps/api/viewsets/connect_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit f4e8a87

Please sign in to comment.