Bug Report
Issue Description
When using the AI Copilot chat feature (particularly streaming responses via /chat/message/stream), the application throws a TypeError in v4.0.4, v4.0.5, and v4.0.6:
TypeError: _insert_message() takes 1 positional argument but 7 were given
Error Details
Error Location: backend_api_python/app/routes/ai_chat.py, line 2118 (and potentially other locations)
Full Error Stack:
2026-07-01 12:38:27,114 - app.utils.db_postgres - ERROR - PostgreSQL operation error (TypeError): _insert_message() takes 1 positional argument but 7 were given
Traceback (most recent call last):
File "/app/app/utils/db_postgres.py", line 430, in get_pg_connection
yield pg_conn
File "/app/app/routes/ai_chat.py", line 2118, in generate
user_message_id = _insert_message(cur, sid, user_id, "user", message or "[image]", attachments, intent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: _insert_message() takes 1 positional argument but 7 were given
Root Cause
The _insert_message() function signature in v4.0.4+ requires all parameters (except cur) to be passed as keyword arguments (marked with * in the function definition at line 377):
def _insert_message(
cur,
*, # <-- This means all following params must be keyword-only
session_id: int,
user_id: int,
role: str,
content: str,
...
) -> int:
However, several function calls still use positional arguments, causing the TypeError.
Affected Versions
- v4.0.4 ❌
- v4.0.5 ❌
- v4.0.6 ❌
- v4.0.3 ✅ (works fine)
Affected Code Locations
-
Line 2024 (in chat_message() function):
user_message_id = _insert_message(cur, sid, user_id, "user", message or "[image]", attachments, intent)
-
Line 2045 (in chat_message() function):
assistant_id = _insert_message(cur, sid, user_id, "assistant", answer, [], intent, actions=parsed.get("actions") or [])
-
Line 2118 (in chat_message_stream() function):
user_message_id = _insert_message(cur, sid, user_id, "user", message or "[image]", attachments, intent)
-
Line 2305 (in chat_message_stream() function - similar issue)
-
Line 2506 (in save_local_chat_message() - needs verification)
Expected Fix
Replace positional arguments with keyword arguments:
# Before (incorrect)
user_message_id = _insert_message(cur, sid, user_id, "user", message or "[image]", attachments, intent)
# After (correct)
user_message_id = _insert_message(
cur,
session_id=sid,
user_id=user_id,
role="user",
content=message or "[image]",
attachments=attachments,
intent=intent,
)
How to Reproduce
- Upgrade to v4.0.4 or later
- Open the AI Copilot chat interface
- Send a message to trigger the chat response (especially stream-based responses)
- The error will be thrown immediately
Workaround
Downgrade to v4.0.3 until this issue is fixed:
image: ghcr.io/brokermr810/quantdinger-backend:v4.0.3
Additional Notes
- The bug appears to have been introduced when the function signature was changed to use keyword-only arguments (via the
* separator)
- v4.0.3 does not have this issue
- The main branch appears to have this fixed already, but the fix was not included in the v4.0.6 release tag
Bug Report
Issue Description
When using the AI Copilot chat feature (particularly streaming responses via
/chat/message/stream), the application throws a TypeError in v4.0.4, v4.0.5, and v4.0.6:Error Details
Error Location:
backend_api_python/app/routes/ai_chat.py, line 2118 (and potentially other locations)Full Error Stack:
Root Cause
The
_insert_message()function signature in v4.0.4+ requires all parameters (exceptcur) to be passed as keyword arguments (marked with*in the function definition at line 377):However, several function calls still use positional arguments, causing the TypeError.
Affected Versions
Affected Code Locations
Line 2024 (in
chat_message()function):Line 2045 (in
chat_message()function):Line 2118 (in
chat_message_stream()function):Line 2305 (in
chat_message_stream()function - similar issue)Line 2506 (in
save_local_chat_message()- needs verification)Expected Fix
Replace positional arguments with keyword arguments:
How to Reproduce
Workaround
Downgrade to v4.0.3 until this issue is fixed:
Additional Notes
*separator)