Expected Behaviour
A time range whose end is earlier than its start on the clock should be treated as crossing midnight regardless of whether the hour digits differ, and only strings that are exactly HH:MM should pass schema validation.
Current Behaviour
Two related defects in the same code path.
- Rollover is detected by comparing hours only (
if int(end_hour) < int(start_hour) in comparators.py). A range like START: "23:30", END: "23:00" has equal hours, so it takes the same-day branch start <= now <= end, which can never be true. The rule silently never matches.
TIME_RANGE_PATTERN is 2[0-3]:[0-5]\d|[0-1]\d:[0-5]\d with no anchors and is used with re.match. "10:00abc" passes validation. At evaluation time int("00abc") raises, _match_by_action swallows the exception and returns False, so the misconfiguration is invisible.
Code snippet
from aws_lambda_powertools.utilities.feature_flags import FeatureFlags, RuleAction
from aws_lambda_powertools.utilities.feature_flags.schema import SchemaValidator
# 1. same-hour rollover: never matches, at any time of day
features = {
"late_night": {
"default": False,
"rules": {
"almost all day": {
"when_match": True,
"conditions": [{
"action": RuleAction.SCHEDULE_BETWEEN_TIME_RANGE.value,
"key": "CURRENT_TIME",
"value": {"START": "23:30", "END": "23:00"},
}],
}
},
}
}
# 2. malformed time passes validation
SchemaValidator({
"f": {"default": False, "rules": {"r": {"when_match": True, "conditions": [{
"action": RuleAction.SCHEDULE_BETWEEN_TIME_RANGE.value,
"key": "CURRENT_TIME",
"value": {"START": "10:00abc", "END": "12:00"},
}]}}}
}).validate() # no error raised
Possible Solution
Compare full minutes-since-midnight (start_h*60+start_m vs end_h*60+end_m) to decide rollover, and anchor the pattern (^(?:2[0-3]|[01]\d):[0-5]\d$) or use fullmatch.
Context: we're porting this utility to Powertools for TypeScript (aws-powertools/powertools-lambda-typescript#5614) and want both runtimes to evaluate the same document identically.
Steps to Reproduce
Run the snippet. For (1), evaluate late_night at any time and observe False. For (2), observe validate() returns without error.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
Expected Behaviour
A time range whose end is earlier than its start on the clock should be treated as crossing midnight regardless of whether the hour digits differ, and only strings that are exactly
HH:MMshould pass schema validation.Current Behaviour
Two related defects in the same code path.
if int(end_hour) < int(start_hour)incomparators.py). A range likeSTART: "23:30", END: "23:00"has equal hours, so it takes the same-day branchstart <= now <= end, which can never be true. The rule silently never matches.TIME_RANGE_PATTERNis2[0-3]:[0-5]\d|[0-1]\d:[0-5]\dwith no anchors and is used withre.match."10:00abc"passes validation. At evaluation timeint("00abc")raises,_match_by_actionswallows the exception and returnsFalse, so the misconfiguration is invisible.Code snippet
Possible Solution
Compare full minutes-since-midnight (
start_h*60+start_mvsend_h*60+end_m) to decide rollover, and anchor the pattern (^(?:2[0-3]|[01]\d):[0-5]\d$) or usefullmatch.Context: we're porting this utility to Powertools for TypeScript (aws-powertools/powertools-lambda-typescript#5614) and want both runtimes to evaluate the same document identically.
Steps to Reproduce
Run the snippet. For (1), evaluate
late_nightat any time and observeFalse. For (2), observevalidate()returns without error.Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs