Skip to content

fix(feature_flags): handle same-hour midnight rollover and reject malformed HH:MM - #8428

Merged
leandrodamascena merged 3 commits into
developfrom
fix/time-range-rollover-and-validation
Sep 14, 2026
Merged

leandrodamascena merged 3 commits into
developfrom
fix/time-range-rollover-and-validation

Conversation

@dreamorosi

@dreamorosi dreamorosi commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Issue number: closes #8423

Summary

Changes

SCHEDULE_BETWEEN_TIME_RANGE now treats any range whose end is earlier than its start on the clock as crossing midnight, and schema validation only accepts values that are exactly HH:MM.

Rollover was decided by comparing hours alone, so a range like START: "23:30", END: "23:00" (equal hours) fell into the same-day branch start <= now <= end, which can never hold. The comparator now compares minutes since midnight.

Separately, TIME_RANGE_PATTERN was unanchored and used with re.match, so "10:00abc" validated and then raised inside int() at evaluation time, where _match_by_action swallows the error and returns False. The pattern is now anchored (^(?:2[0-3]|[01]\d):[0-5]\d$) so the misconfiguration surfaces as a SchemaValidationError.

Regression tests cover a same-hour overnight range at a time inside it (10:00) and at the only uncovered gap (23:15), plus malformed START/END strings with trailing or leading garbage and extra digits. All four new cases fail against the previous code.

This also aligns evaluation with the TypeScript port in aws-powertools/powertools-lambda-typescript#5614.

User experience

Before

  • A rule with {"START": "23:30", "END": "23:00"} silently never matched, at any time of day.
  • A rule with {"START": "10:00abc", "END": "12:00"} passed SchemaValidator().validate() and then silently evaluated to False.

After

  • {"START": "23:30", "END": "23:00"} matches from 23:30 through 23:00 the next day, i.e. everything except 23:00-23:30.
  • {"START": "10:00abc", "END": "12:00"} raises SchemaValidationError: 'START' and 'END' must be a valid time format, time_format=%H:%M, rule=... at validation time.

Existing valid HH:MM configurations are unaffected.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…formed HH:MM

SCHEDULE_BETWEEN_TIME_RANGE decided whether a range crossed midnight by
comparing hours only, so a range like 23:30 -> 23:00 (equal hours) took
the same-day branch and could never match. Compare minutes since midnight
instead.

TIME_RANGE_PATTERN was unanchored and used with re.match, so values such
as "10:00abc" passed schema validation and then failed silently at
evaluation time. Anchor the pattern so only exact HH:MM strings validate.

Fixes #8423
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 3, 2026
@boring-cyborg boring-cyborg Bot added the tests label Sep 3, 2026
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.65%. Comparing base (23017e0) to head (f96f47b).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8428   +/-   ##
========================================
  Coverage    96.65%   96.65%           
========================================
  Files          296      296           
  Lines        14896    14898    +2     
  Branches      1265     1265           
========================================
+ Hits         14398    14400    +2     
  Misses         363      363           
  Partials       135      135           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dreamorosi
dreamorosi marked this pull request as ready for review September 3, 2026 16:26
@dreamorosi
dreamorosi requested a review from a team as a code owner September 3, 2026 16:26
@dreamorosi
dreamorosi requested review from hjgraca and leandrodamascena and removed request for hjgraca September 3, 2026 16:26
@leandrodamascena

Copy link
Copy Markdown
Contributor

I'll review this by tomorrow.

@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Andrea, this looks good. I pushed a small follow-up to use fullmatch(), since Python’s $ still accepts a final newline.

Valid HH:MM configurations are not affected. Invalid values are now rejected as expected, and the rollover fix behaves correctly. I’ll merge this.

@mergify

mergify Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@leandrodamascena
leandrodamascena merged commit 3fff06f into develop Sep 14, 2026
15 checks passed
@leandrodamascena
leandrodamascena deleted the fix/time-range-rollover-and-validation branch September 14, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: SCHEDULE_BETWEEN_TIME_RANGE mishandles same-hour midnight rollover and accepts malformed HH:MM

2 participants