diff --git a/borrowing_service/signals.py b/borrowing_service/signals.py index 7dc418e..9197fc9 100644 --- a/borrowing_service/signals.py +++ b/borrowing_service/signals.py @@ -10,13 +10,16 @@ @receiver(post_save, sender=Borrowing) def notify_new_borrowing(sender, instance, created, **kwargs): if created: - borrowing_info = ( - "New borrowing created:\n\n" - f"-Book: {instance.book}\n" - f"--Borrow date: {instance.borrow_date}\n" - f"--Expected return date: {instance.expected_return_date}\n" - ) - send_notification( - TelegramUser.objects.get(user_id=instance.user_id).chat_id, - borrowing_info - ) + try: + borrowing_info = ( + "New borrowing created:\n\n" + f"-Book: {instance.book}\n" + f"--Borrow date: {instance.borrow_date}\n" + f"--Expected return date: {instance.expected_return_date}\n" + ) + send_notification( + TelegramUser.objects.get(user_id=instance.user_id).chat_id, + borrowing_info + ) + except TelegramUser.DoesNotExist: + pass