Catch some tracebacks

This commit is contained in:
Finn Stutzenstein 2020-10-28 08:18:20 +01:00
parent 7277a1bb01
commit 582215042d
No known key found for this signature in database
GPG Key ID: 9042F605C6324654
2 changed files with 12 additions and 2 deletions

View File

@ -6,6 +6,7 @@ from django.contrib.auth import get_user_model
from django.db import transaction
from django.db.models import Case, When
from django.db.models.deletion import ProtectedError
from django.db.utils import IntegrityError
from django.http.request import QueryDict
from rest_framework import status
@ -514,7 +515,10 @@ class MotionViewSet(TreeSortMixin, ModelViewSet):
and not motion.is_supporter(request.user)
):
raise ValidationError({"detail": "You can not support this motion."})
motion.supporters.add(request.user)
try:
motion.supporters.add(request.user)
except IntegrityError:
raise ValidationError({"detail": "You are already a supporter."})
# Send new supporter via autoupdate because users without permission
# to see users may not have it but can get it now.
# TODO: Skip history.

View File

@ -6,6 +6,7 @@ from django.db import models
from . import logging
from .access_permissions import BaseAccessPermissions
from .auth import UserDoesNotExist
from .autoupdate import AutoupdateElement, inform_changed_data, inform_elements
from .rest_api import model_serializer_classes
from .utils import convert_camel_case_to_pseudo_snake_case, get_element_id
@ -185,7 +186,12 @@ class RESTModelMixin:
"""
Converts a list of elements from full_data to restricted_data.
"""
return await cls.get_access_permissions().get_restricted_data(elements, user_id)
try:
return await cls.get_access_permissions().get_restricted_data(
elements, user_id
)
except UserDoesNotExist:
return []
def get_full_data(self) -> Dict[str, Any]:
"""