Bug: SCHEDULE_BETWEEN_DAYS_OF_WEEK stops matching when LC_TIME is not English
Expected Behaviour
A SCHEDULE_BETWEEN_DAYS_OF_WEEK rule with "DAYS": ["FRIDAY"] matches on Fridays whatever locale the function runs with.
Current Behaviour
compare_days_of_week gets the current day with strftime("%A").upper(), which names the day in the process's LC_TIME locale. If the function calls locale.setlocale(locale.LC_TIME, ...) (or LC_ALL) for a non-English locale, the day comes back as FREITAG, VENDREDI, etc., never equals the English names the schema requires, and every day-of-week rule silently stops matching.
Code snippet
import locale
from aws_lambda_powertools.utilities.feature_flags.comparators import compare_days_of_week
cond = {"DAYS": ["FRIDAY"], "TIMEZONE": "UTC"} # run on a Friday
compare_days_of_week(None, cond) # True
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
compare_days_of_week(None, cond) # False, the current day is "FREITAG"
Steps to Reproduce
- Configure a feature flag rule with
SCHEDULE_BETWEEN_DAYS_OF_WEEKand today's day inDAYS. - Set a non-English
LC_TIMEin the function. - Evaluate the flag: the rule no longer matches.
Possible Solution
Look the day up from datetime.weekday() (Monday is 0) instead of formatting its name, so the result does not depend on the locale. I can open a PR.
Powertools for AWS Lambda (Python) version
latest (develop, 3.38.0)
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
No response
Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link
Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out our GitHub Discussions: Join the conversation
Thanks @anishmehta24, confirmed with de_DE here, the day comes back as FREITAG. Honestly most people never touch the locale in Lambda, but comparing against weekday() is the right thing anyway. I'll review #8707. Goes into 3.40.0.
[!warning] This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either reopen the issue, or open a new issue referencing this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
This is now released under 3.40.0 version!