From 250b69db8ccbfab0dcccdce3f94ea35162b9ca1f Mon Sep 17 00:00:00 2001 From: busya Date: Fri, 5 Jun 2026 11:23:53 +0300 Subject: [PATCH] 032: fix coroutine never awaited in debug.py + task_logger.py debug.py: _test_db_api and _get_dataset_structure were already async def but called SupersetClient methods (authenticate, get_databases, get_dataset) without await. Added await to 4 calls. task_logger.py: _add_log callback is async def but _log() called it without await, silently dropping all task log messages (RuntimeWarning: coroutine never awaited). Changed to fire-and-forget via asyncio.ensure_future when a running event loop is available, drops gracefully otherwise. --- backend/src/core/task_manager/task_logger.py | 11 ++++++++++- backend/src/plugins/debug.py | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/src/core/task_manager/task_logger.py b/backend/src/core/task_manager/task_logger.py index cb3c894a..4a77f051 100644 --- a/backend/src/core/task_manager/task_logger.py +++ b/backend/src/core/task_manager/task_logger.py @@ -4,6 +4,7 @@ # @RELATION DEPENDS_ON -> [TaskManager] # @RELATION DEPENDS_ON -> [EventBus] # @INVARIANT Each TaskLogger instance is bound to a specific task_id and default source. +import asyncio from collections.abc import Callable from typing import Any @@ -81,13 +82,21 @@ class TaskLogger: metadata: dict[str, Any] | None = None, ) -> None: """Internal logging method.""" - self._add_log( + coro = self._add_log( task_id=self._task_id, level=level, message=message, source=source or self._default_source, metadata=metadata, ) + # Fire-and-forget: schedule the async callback if a loop is running, + # otherwise drop gracefully (sync context, no event loop available). + try: + loop = asyncio.get_running_loop() + if loop.is_running(): + asyncio.ensure_future(coro) + except RuntimeError: + pass # #endregion _log # #region debug [TYPE Function] # @PURPOSE: Log a DEBUG level message. diff --git a/backend/src/plugins/debug.py b/backend/src/plugins/debug.py index 9e89a282..286425b3 100644 --- a/backend/src/plugins/debug.py +++ b/backend/src/plugins/debug.py @@ -167,8 +167,8 @@ class DebugPlugin(PluginBase): raise ValueError(f"Environment '{name}' not found.") client = SupersetClient(env_config) - client.authenticate() - count, dbs = client.get_databases() + await client.authenticate() + count, dbs = await client.get_databases() log.debug(f"Found {count} databases in {name}") results[name] = { "count": count, @@ -203,9 +203,9 @@ class DebugPlugin(PluginBase): raise ValueError(f"Environment '{env_name}' not found.") client = SupersetClient(env_config) - client.authenticate() + await client.authenticate() - dataset_response = client.get_dataset(dataset_id) + dataset_response = await client.get_dataset(dataset_id) log.debug(f"Retrieved dataset structure for {dataset_id}") return dataset_response.get('result') or {} # endregion _get_dataset_structure