From d93cb6265fb567b037cf2148e5f9c45ea49d6f89 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Wed, 8 Jul 2026 13:11:17 +0000 Subject: [PATCH] refactor: Eagerly import celery_app to ensure proper configuration in production Updated the import mechanism for celery_app to avoid issues with lazy-loading, ensuring the default Celery app is correctly configured in production environments. Removed the __getattr__ function for celery_app, simplifying the module structure. --- dispatcharr/__init__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/dispatcharr/__init__.py b/dispatcharr/__init__.py index 2f688176..cc07df3d 100644 --- a/dispatcharr/__init__.py +++ b/dispatcharr/__init__.py @@ -1,11 +1,9 @@ # dispatcharr/__init__.py +# For Celery: import eagerly so @shared_task binds to the configured app. +# Lazy-loading via __getattr__ left the default Celery app unconfigured in +# production (no CELERY_BROKER_URL in env), so .delay() fell back to AMQP +# localhost and failed with ConnectionRefusedError. +from .celery import app as celery_app + __all__ = ("celery_app",) - - -def __getattr__(name: str): - if name == "celery_app": - from .celery import app as celery_app - - return celery_app - raise AttributeError(f"module {__name__!r} has no attribute {name!r}")