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

duplicate_registration_id logger #1

Merged
merged 2 commits into from
Jun 19, 2023
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
17 changes: 16 additions & 1 deletion push_notifications/api/rest_framework.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import logging

from django.db import IntegrityError
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

from rest_framework import permissions, status
from rest_framework.fields import IntegerField
from rest_framework.response import Response
Expand Down Expand Up @@ -153,7 +159,16 @@ def create(self, request, *args, **kwargs):
self.perform_update(serializer)
return Response(serializer.data)
else:
self.perform_create(serializer)
try:
self.perform_create(serializer)
except IntegrityError:
instance = self.queryset.model.objects.filter(
registration_id=request.data[self.lookup_field]
).first()
if instance:
logger.error(f"registration_id already exist {instance.registration_id} user: {instance.user} created time for that {instance.date_created}", exc_info=True)
else:
logger.error(f"registration_id that already exist {instance}", exc_info=True)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)

Expand Down