From a0bc94d7ecd424b33a367d03238bfb2b8544df8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Trkan?= Date: Thu, 2 Oct 2025 13:04:30 +0200 Subject: [PATCH] Update backend/app/workers/queue_worker.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- backend/app/workers/queue_worker.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/backend/app/workers/queue_worker.py b/backend/app/workers/queue_worker.py index ba65f6a..a10b4c4 100644 --- a/backend/app/workers/queue_worker.py +++ b/backend/app/workers/queue_worker.py @@ -82,17 +82,15 @@ def _auto_import_handlers() -> None: if pkg_name: bases_to_try.append(pkg_name) - # If executed as a script (no package), make 'app' importable and alias this - # module as 'app.workers.queue_worker' so that handler relative imports work + # If executed as a script (no package), make 'app' importable so that handler modules + # can be imported using absolute imports. Handler modules must use absolute imports + # (e.g., 'from backend.app.workers.queue_worker import register_task_handler'). if not pkg_name: - backend_dir = os.path.abspath(os.path.join(__file__, '../../..')) # .../backend + backend_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) # .../backend if backend_dir not in sys.path: sys.path.insert(0, backend_dir) try: importlib.import_module("app.workers") - # Alias the current module under the package name to satisfy - # 'from .queue_worker import ...' inside handlers without re-importing - sys.modules.setdefault("app.workers.queue_worker", sys.modules[__name__]) except Exception as e: logger.debug("Failed to prepare package context for handlers: %s", e) # Ensure we try importing under 'app.workers'