Skip to content

Commit

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

Please sign in to comment.