diff --git a/app/__init__.py b/app/__init__.py index ef46fdb87..42d585ac6 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -285,12 +285,13 @@ def init_app(application): @application.context_processor def _attach_current_global_daily_messages(): remaining_global_messages = 0 - if current_app: service_id = session.get("service_id") - global_limit = current_app.config["GLOBAL_SERVICE_MESSAGE_LIMIT"] - global_messages_count = service_api_client.get_global_notification_count(service_id) - remaining_global_messages = global_limit - global_messages_count + + if service_id: + global_limit = current_app.config["GLOBAL_SERVICE_MESSAGE_LIMIT"] + global_messages_count = service_api_client.get_global_notification_count(service_id) + remaining_global_messages = global_limit - global_messages_count.get("count") return {"daily_global_messages_remaining": remaining_global_messages} @application.before_request diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 25b9d7c6e..c5b5ceb08 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -498,7 +498,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): return int(count) def get_global_notification_count(self, service_id): - return self.get("/service/{}/notification-count".format(service_id)) + return self.get("/service/{}/notification-count".format(service_id)) service_api_client = ServiceAPIClient()