Repository navigation
Description
Summary
db/agent_settings/sharing.py:206 raises AttributeError: 'NoneType' object has no attribute 'lower' when the agent owner's users.email is NULL. This blocks any proactive messaging operation (auth check, rate-limit check, delivery) for agents owned by users without an email — the admin user is the canonical example on fresh installs.
Component
Backend / agent sharing / proactive messaging
Priority
P2 — silently breaks the entire POST /api/agents/{name}/messages surface for admin-owned agents. Returns generic HTTP 500 "Internal error sending message", which is also a DX/observability regression.
Root cause
# src/backend/db/agent_settings/sharing.py:206
owner_user = self._user_ops.get_user_by_username(owner["owner_username"])
if owner_user and owner_user.get("email", "").lower() == email.lower():
return Truedict.get(key, default) returns the default only if the key is absent. When the key exists but the value is None (NULL column), .get() returns None and .lower() crashes.
Reproduction
# 1. Agent owned by admin (admin.email is NULL by default)
curl -X POST http://localhost:8000/api/agents/blank-agent/messages \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"recipient_email":"[email protected]","text":"hi","channel":"telegram"}'
# -> HTTP 500 {"detail":"Internal error sending message"}Backend log:
ERROR routers.messages: Proactive message failed: 'NoneType' object has no attribute 'lower'
File "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'
Suggested fix
One line:
if owner_user and (owner_user.get("email") or "").lower() == email.lower():Related
- Discovered while verifying the bug: PlatformAuditService missing 'log_event' method #374 / fix(audit): log() not log_event() in proactive messages (#374) #416 fix for proactive-message audit logging. The audit bug and this bug are independent: the crash here short-circuits the authorization check before
_audit_sendruns. - Likely worth grepping for the same
.get(key, "").lower()or.get(key, "").strip()pattern elsewhere — same Python pitfall.
Acceptance criteria
-
can_agent_message_emailreturnsFalse(no crash) when owner has NULL email and recipient ≠ owner. - Admin-owned
POST /api/agents/{name}/messageswith non-opted-in recipient returns clean 403not_authorizedand writes aproactive_messageaudit row. - Regression unit test covering NULL-email owner.
- Grep sweep for identical
.get("<col>", "").lower()/.strip()pattern in the codebase.
Environment
- Trinity version: current
main(rev88e5525)
Activity
fix(sharing): coerce NULL owner email before .lower() (#417)
fix(sharing): coerce NULL owner email before .lower() (#417)
dolho commentedon Apr 20, 2026
Duplicate of #372 — fixed on main by commit d961621 (Apr 17, 2026) with identical
(x or "")coercion. Filed this after rebasing, hadn't noticed the existing fix.The regression test from PR #416 (
tests/test_sharing_null_email_unit.py) still lands as a useful hardening — #372 shipped the fix without a unit test.fix(audit): log() not log_event() in proactive messages (#374) (#416)