fix: handle None from Redis in sent_messages counter

When Redis keys are missing (after FLUSHALL, restart, or for new
mailboxes/domains), hget() returns None. The sent_messages property
in MessageLimitMixin now treats a missing counter as zero messages
sent, preventing TypeError on /api/v2/accounts/ and /api/v2/domains/.
This commit is contained in:
John Winter Murphy
2026-03-04 18:36:19 +01:00
committed by Christophe CHAUVET
parent f230d0247a
commit 55e86fe3f4
+4 -1
View File
@@ -17,7 +17,10 @@ class MessageLimitMixin:
"""Return number of sent messages for the current day."""
if self.message_limit is None:
return None
return self.message_limit - get_message_counter(self.message_counter_key)
counter = get_message_counter(self.message_counter_key)
if counter is None:
return 0
return self.message_limit - counter
@property
def sent_messages_in_percent(self) -> Optional[int]: # noqa