From 24fb384cf92dd33c3a7db9fcb0fd9b0af352a5fb Mon Sep 17 00:00:00 2001 From: Agent Zero Date: Mon, 27 Jul 2026 02:39:16 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20keep=20=5F=5Fannotations=5F=5F=20in=20wr?= =?UTF-8?q?ap=5Fplugin=5Froute=20=E2=80=94=20body=20params=20need=20Forwar?= =?UTF-8?q?dRef=20resolution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing __annotations__ broke body parameter resolution: FastAPI could not resolve ForwardRef('ConversationCreate') etc. causing 422 on all POST routes with body params. Now keeping annotations from functools.wraps and only removing return_annotation. --- app/core/plugin_error_handler.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/core/plugin_error_handler.py b/app/core/plugin_error_handler.py index 1d41aa7..69ef23f 100644 --- a/app/core/plugin_error_handler.py +++ b/app/core/plugin_error_handler.py @@ -3,7 +3,7 @@ import logging import functools import inspect from fastapi import UploadFile # noqa: F401 — needed for ForwardRef resolution -from fastapi import WebSocket # noqa: F401 — needed for ForwardRef resolution of WebSocket params +from fastapi import WebSocket # noqa: F401 — needed for ForwardRef resolution from fastapi.responses import JSONResponse logger = logging.getLogger(__name__) @@ -14,7 +14,8 @@ def wrap_plugin_route(handler): Copies the original handler's signature so FastAPI sees the correct parameters (path params, query params, body, etc.) instead of *args/**kwargs. - Removes return annotation to prevent ForwardRef('UploadFile') resolution issues. + UploadFile and WebSocket are imported in this module's namespace so + FastAPI can resolve ForwardRef('UploadFile') and ForwardRef('WebSocket'). """ @functools.wraps(handler) async def wrapper(*args, **kwargs): @@ -26,18 +27,16 @@ def wrap_plugin_route(handler): status_code=500, content={'detail': f'Plugin error: {exc}', 'code': 'plugin_error'} ) - # Remove annotations that cause ForwardRef resolution issues - wrapper.__annotations__ = {} # Remove __wrapped__ so FastAPI doesn't try to resolve the original signature + # through the wrapper chain — we set __signature__ explicitly instead. if hasattr(wrapper, '__wrapped__'): delattr(wrapper, '__wrapped__') - # Copy the signature from the original handler but remove return annotation + # Copy the signature from the original handler so FastAPI sees correct params. + # Keep __annotations__ from functools.wraps (needed for ForwardRef resolution). + # Remove only the return annotation to avoid response_model issues. try: orig_sig = inspect.signature(handler) - # Create new signature without return annotation - new_params = list(orig_sig.parameters.values()) wrapper.__signature__ = orig_sig.replace( - parameters=new_params, return_annotation=inspect.Signature.empty, ) except (ValueError, TypeError):