From 4f85e7c089aaa8c5bbfacb963ce8f0faa3ffa56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Fri, 8 May 2026 14:36:16 -0700 Subject: [PATCH] Fix pyright cr_code access on Coroutine in BaseObject.create_task `collections.abc.Coroutine` doesn't expose `cr_code`/`co_name`; only native coroutine objects do. Use `getattr` chains so pyright is happy and any non-native awaitable falls back to a generic task name instead of crashing. --- src/pipecat/utils/base_object.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pipecat/utils/base_object.py b/src/pipecat/utils/base_object.py index 6733d9106..af68abb59 100644 --- a/src/pipecat/utils/base_object.py +++ b/src/pipecat/utils/base_object.py @@ -133,11 +133,12 @@ class BaseObject(ABC): Returns: The created asyncio task. """ - if name: - name = f"{self}::{name}" - else: - name = f"{self}::{coroutine.cr_code.co_name}" - return self.task_manager.create_task(coroutine, name) + if not name: + # Native coroutines expose ``cr_code``; fall back to a generic + # name for any other awaitable subtype. + cr_code = getattr(coroutine, "cr_code", None) + name = getattr(cr_code, "co_name", "task") + return self.task_manager.create_task(coroutine, f"{self}::{name}") async def cancel_task(self, task: asyncio.Task, timeout: float | None = 1.0): """Cancel a task managed by this object's task manager.