From ff2f60f7f3d6e74a5e45d1de118bcc852a064e3b Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Sun, 4 Aug 2024 18:29:43 +0200 Subject: [PATCH] [FIX] Avoid `KeyError` in `celery_settings` checks --- allianceauth/checks.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/allianceauth/checks.py b/allianceauth/checks.py index 057efd36..cae9e01b 100644 --- a/allianceauth/checks.py +++ b/allianceauth/checks.py @@ -161,11 +161,19 @@ def sql_settings(app_configs, **kwargs) -> List[CheckMessage]: @register() def celery_settings(app_configs, **kwargs) -> List[CheckMessage]: errors: List[CheckMessage] = [] - if current_app.conf.broker_transport_options != {'priority_steps': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'queue_order_strategy': 'priority'}: - errors.append(Error("Celery Priorities are not set correctly", hint="https://gitlab.com/allianceauth/allianceauth/-/commit/8861ec0a61790eca0261f1adc1cc04ca5f243cbc", id="allianceauth.checks.B003")) - if current_app.conf.broker_connection_retry_on_startup != True: - errors.append(Error("Celery broker_connection_retry_on_startup not set correctly", hint="https://gitlab.com/allianceauth/allianceauth/-/commit/380c41400b535447839e5552df2410af35a75280", id="allianceauth.checks.B004")) + try: + if current_app.conf.broker_transport_options != {'priority_steps': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'queue_order_strategy': 'priority'}: + errors.append(Error("Celery Priorities are not set correctly", hint="https://gitlab.com/allianceauth/allianceauth/-/commit/8861ec0a61790eca0261f1adc1cc04ca5f243cbc", id="allianceauth.checks.B003")) + except KeyError: + errors.append(Error("Celery Priorities are not set", hint="https://gitlab.com/allianceauth/allianceauth/-/commit/8861ec0a61790eca0261f1adc1cc04ca5f243cbc", id="allianceauth.checks.B003")) + + try: + if current_app.conf.broker_connection_retry_on_startup != True: + errors.append(Error("Celery broker_connection_retry_on_startup not set correctly", hint="https://gitlab.com/allianceauth/allianceauth/-/commit/380c41400b535447839e5552df2410af35a75280", id="allianceauth.checks.B004")) + except KeyError: + errors.append(Error("Celery broker_connection_retry_on_startup not set", hint="https://gitlab.com/allianceauth/allianceauth/-/commit/380c41400b535447839e5552df2410af35a75280", id="allianceauth.checks.B004")) + return errors