mirror of
https://github.com/modoboa/modoboa.git
synced 2026-04-26 01:16:01 +03:00
[GH-ISSUE #3910] Bug: DMARC alignment_stats period week is shifted due to mixing isocalendar() and %W #1932
Labels
No labels
bug
bug
dependencies
design
documentation
duplicate
enhancement
enhancement
enhancement
feedback-needed
help-needed
help-needed
installer
invalid
looking-for-sponsors
modoboa-contacts
new-ui
new-ui
pr
pull-request
pyconfr
python
question
security
stale
webmail
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/modoboa-modoboa#1932
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jg-shinji-ueda on GitHub (Feb 9, 2026).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/3910
Impacted versions
Steps to reproduce
periodvalues.Example requests (replace host/domain IDs as needed):
Request:
https://mail.example.com/api/v2/domains/2/dmarc/alignment_stats/?period=2026-5
Response: non-empty stats
Request:
https://mail.example.com/api/v2/domains/2/dmarc/alignment_stats/?period=2026-6
Response:
{"aligned":{},"trusted":{},"forwarded":{},"failed":{}}
Request:
https://mail.example.com/api/v2/domains/2/dmarc/alignment_stats/?period=2026-7
Response:
{"aligned":{},"trusted":{},"forwarded":{},"failed":{}}
Current behavior
period=YYYY-WWappears to represent a week, but the computed week range is inconsistent / shifted by one week.Evidence: DB data range (Reports exist only through 2026-02-07 UTC)
Report range example:
Daily counts example:
Report by day:
Record by report.start_date day:
Evidence: the UI week shown for "2026-06"
When requesting
period=2026-6, the UI indicates the week range:2026/2/2 - 2026/2/8 (week view)
However, the backend interpretation can shift depending on ISO week vs
%Wweek numbering.Evidence: actual report count in the "UI week range"
For the week window 2026-02-02 .. 2026-02-08 (UTC range [2026-02-02, 2026-02-09)):
For the next week window 2026-02-09 .. 2026-02-15 (UTC range [2026-02-09, 2026-02-16)):
So a one-week shift explains why one
periodvalue returns data and the next returns empty.Root cause analysis (code-level)
In Modoboa 2.6.5,
alignment_statscalls:timezone.now().isocalendar() (ISO week)
datetime.strptime(..., "%Y-%W-%w") (%W week numbering)
This mixes ISO week numbering and
%Wweek numbering. The sameYYYY-WWcan point to different date ranges.Concrete example (Python):
ISO week:
%W week:
Therefore, depending on which definition is used, the "week number" shifts by one week around this boundary.
Expected behavior
The meaning of
period=YYYY-WWshould be clearly defined (ISO week or%Wweek numbering) and handled consistently end-to-end.Proposal: backward compatible fix (A + period_mode)
To clarify period definition while keeping backward compatibility:
period_mode:periodas ISO-8601 week numberperiodas%Wweek number (legacy)periodis omitted (default previous week), compute the "previous week" using the SAME mode as week_range uses, to avoid mixing isocalendar() with %W.Alternative possible approach:
periodvalues that match backend semantics.However, because backend currently mixes ISO and %W, backend contract definition should be clarified first.
Note: We investigated this behavior with the help of ChatGPT and summarized the findings here to speed up triage and reproduction.