| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…range month with a 24:00 time The 24:00 midnight-rollover path validated only the upper month bound before calling days_in_month(), so a month below 1 reached assert(month >= 1) on a debug build (and AssertionError in the pure Python implementation). Add the missing lower bound to both so an out-of-range month consistently raises ValueError.
There was a problem hiding this comment.
Just a few little nits, the core change is correct.
While we're dealing with this assert, can you please update it (on L58) like so:
- assert 1 <= month <= 12, month
+ assert 1 <= month <= 12, f"month must be in 1..12, not {month}"
Sorry, something went wrong.
| Fix :meth:`datetime.datetime.fromisoformat` raising an unexpected error on an | ||
| out-of-range month combined with a ``24:00`` time, such as | ||
| ``"2009-00-01T24:00:00"``. It now consistently raises :exc:`ValueError`. |
There was a problem hiding this comment.
| Fix :meth:`datetime.datetime.fromisoformat` raising an unexpected error on an | |
| out-of-range month combined with a ``24:00`` time, such as | |
| ``"2009-00-01T24:00:00"``. It now consistently raises :exc:`ValueError`. | |
| Fix :meth:`datetime.datetime.fromisoformat` raising :exc:`AssertionError` | |
| instead of :exc:`ValueError` for an out-of-range month combined with a | |
| ``24:00`` time. |
Sorry, something went wrong.
| "2009-04-01T12:30:90", # Second out of range | ||
| "2009-04-01T12:90:45", # Minute out of range | ||
| "2009-04-01T25:30:45", # Hour out of range | ||
| "2009-00-01T24:00:00", # Month out of range (below) |
There was a problem hiding this comment.
| "2009-00-01T24:00:00", # Month out of range (below) | |
| "2009-00-01T24:00:00", # Month below range |
Sorry, something went wrong.
|
Thanks @StanFromIreland — applied all three. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
|
Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
Sorry, something went wrong.
|
GH-151809 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
|
Sorry, @tonghuaroot and @StanFromIreland, I could not cleanly backport this to 3.13 due to a conflict. cherry_picker 1fb874cc076e771c39a7bbc650dce386e3c5b7a0 3.13 |
Sorry, something went wrong.
|
GH-151810 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
@tonghuaroot are you able to do the backport (see bot comment above)? |
Sorry, something went wrong.
|
Thanks @StanFromIreland! I looked into the 3.13 backport and I don't think it's applicable there. On 3.13, datetime.fromisoformat() doesn't support a 24:00 time at all — it rejects hour 24 as out of range before any month handling: >>> datetime.fromisoformat('9999-12-31T24:00:00') # 3.13
ValueError: hour must be in 0..23The 24:00 → next-day normalization that this fix touches (the became_next_day path) was only added in 3.14 via gh-102450 / #105856, which merged after 3.13 had already branched, so the out-of-range-month-with-24:00 case can't occur on 3.13 — the out-of-range month is already rejected cleanly there: >>> datetime.fromisoformat('2009-13-01T24:00:00') # 3.13
ValueError: month must be in 1..12That's why the cherry-pick conflicts: the whole code path the patch modifies isn't present on 3.13. I think the needs backport to 3.13 label can be dropped. Happy to do the backport if I've missed something. |
Sorry, something went wrong.
|
Thanks for checking! |
Sorry, something went wrong.
…nth w/ a 24:00 time (python#151771) Co-authored-by: Stan Ulbrych <stan@python.org>
| Back | FazBrowse Home | New Git URL |
datetime.fromisoformat() reached days_in_month() with month == 0 when the input combined an out-of-range (below 1) month with a 24:00 time, for example "2009-00-01T24:00:00". On a --with-pydebug build this tripped assert(month >= 1) in days_in_month (Modules/_datetimemodule.c); the pure-Python implementation in Lib/_pydatetime.py raised AssertionError on the same input. On a release build both already raised ValueError.
The 24:00 midnight-rollover guard validated only the upper month bound (month <= 12) before the days_in_month() call, and the parser does not range-check the month before that point, so a month below 1 slipped through. The matching upper-bound input "2009-13-01T24:00:00" was already rejected by the month <= 12 check.
This adds the missing month >= 1 lower bound to the guard in both implementations (mirroring the existing check_date_args validation), so an out-of-range month consistently raises ValueError. A regression test is added next to the existing out-of-range-month case in datetimetester.py.