Repository navigation
Closed
Labels
Description
Summary
Proactive messaging via Telegram fails with HTTP 500 when the agent owner's email is NULL in the database. The can_agent_message_email function calls .lower() on a None value, causing an AttributeError. This blocks all proactive messaging for agents whose owners have NULL email fields.
Component
Backend / Database / Agent Sharing
Priority
P1
Error
AttributeError: 'NoneType' object has no attribute 'lower'
File "/app/routers/messages.py", line 98, in send_proactive_message
result = await proactive_message_service.send_message(
File "/app/services/proactive_message_service.py", line 186, in send_message
if not db.can_agent_message_email(agent_name, recipient_email):
File "/app/database.py", line 397, in can_agent_message_email
return self._agent_ops.can_agent_message_email(agent_name, email)
File "/app/db/agent_settings/sharing.py", line 206, in can_agent_message_email
if owner_user and owner_user.get("email", "").lower() == email.lower():
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'lower'
Location
- File:
src/backend/db/agent_settings/sharing.py - Line: 206
- Function/Class:
can_agent_message_email
Root Cause
The code uses owner_user.get("email", "") expecting an empty string as default when email is missing. However, .get() only returns the default when the key is absent - when the key exists but the value is NULL/None, it returns None. Calling .lower() on None raises AttributeError.
Reproduction Steps
- Have an agent whose owner has a NULL email field in the users table
- Agent attempts to send a proactive message (e.g., via Telegram)
- Backend returns HTTP 500
- Check logs: AttributeError on
.lower()call
Suggested Fix
Use or "" pattern to handle both missing keys and NULL values:
# In db/agent_settings/sharing.py line 206
# BEFORE:
if owner_user and owner_user.get("email", "").lower() == email.lower():
# AFTER:
owner_email = owner_user.get("email") or ""
if owner_user and owner_email.lower() == email.lower():Or inline:
if owner_user and (owner_user.get("email") or "").lower() == email.lower():Environment
- Trinity version:
4bde5d5 - Docker version: 24.x
- OS: Ubuntu 22.04
Related
src/backend/db/agent_settings/sharing.pysrc/backend/services/proactive_message_service.pysrc/backend/routers/messages.py
Activity
fix(db): handle NULL email in can_agent_message_email check