Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BF(workaround): to avoid crash for user lacking metadata - return INCOMPLETE #1086

Merged
merged 1 commit into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions dandiapi/api/views/users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import logging

from allauth.socialaccount.models import SocialAccount
from django.contrib.auth.models import User
from django.db.models import Q
Expand All @@ -15,6 +17,19 @@
from dandiapi.api.permissions import IsApproved
from dandiapi.api.views.serializers import UserDetailSerializer, UserSerializer

logger = logging.getLogger(__name__)


def _get_user_status(user: User):
# Workaround for https://github.com/dandi/dandi-archive/issues/1085
# TODO: remove/robustify some other way whenever underlying reason is
# identified
metadata = getattr(user, 'metadata', None)
if metadata:
return metadata.status
logger.error("User %s lacks .metadata. Returning user's status as INCOMPLETE", user)
return UserMetadata.Status.INCOMPLETE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djarecka make it here

Suggested change
return UserMetadata.Status.INCOMPLETE
return UserMetadata.Status.APPROVED

if you want to allow that user to be able to click 'Create dataset' etc



def user_to_dict(user: User):
"""
Expand All @@ -26,7 +41,7 @@ def user_to_dict(user: User):
'admin': user.is_superuser,
'username': user.username,
'name': f'{user.first_name} {user.last_name}'.strip(),
'status': user.metadata.status,
'status': _get_user_status(user),
'created': user.date_joined,
}

Expand All @@ -46,7 +61,7 @@ def social_account_to_dict(social_account: SocialAccount):
'admin': user.is_superuser,
'username': username,
'name': name,
'status': user.metadata.status,
'status': _get_user_status(user),
'created': created,
}

Expand Down