mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
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:
committed by
Christophe CHAUVET
parent
f230d0247a
commit
55e86fe3f4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user