diff --git a/manage_notifications/api/cron_views.py b/manage_notifications/api/cron_views.py index d9fdea3..be5d45e 100644 --- a/manage_notifications/api/cron_views.py +++ b/manage_notifications/api/cron_views.py @@ -24,6 +24,11 @@ class OneWeekSubscriptionAlertView(APIView): eligible_principals = self.eligible_principals() for principal in eligible_principals: + try: + player_id = principal.principal.player_id + except AttributeError: + # Handle the case where principal is null or does not have a player_id field + continue notification_title = "Subscription Expiry Reminder" notification_message = "Your subscription is going to expire in a week." notification_category = NotificationCategoryChoices.SUBSCRIPTION @@ -32,7 +37,7 @@ class OneWeekSubscriptionAlertView(APIView): notification_payload = { "headings": {"en": notification_title}, "contents": {"en": notification_message}, - "include_player_ids": [principal.player_id], + "include_player_ids": [player_id], } response = self.client.send_notification(notification_payload)