Skip to content

Don't crash on a blank PO-Revision-Date/POT-Creation-Date header - #1347

Open
Tatamis wants to merge 1 commit into
python-babel:masterfrom
Tatamis:fix/blank-revision-date-crash
Open

Tatamis wants to merge 1 commit into
python-babel:masterfrom
Tatamis:fix/blank-revision-date-crash

Conversation

@Tatamis

@Tatamis Tatamis commented Sep 17, 2026

Copy link
Copy Markdown

Fixes #1219.

Bug

Some tools (e.g. Poedit) leave PO-Revision-Date or POT-Creation-Date blank in a .po file's header, instead of eliding the header or using the YEAR-MO-DA HO:MI+ZONE placeholder. _parse_datetime_header() passes that blank value straight to datetime.strptime(), which crashes:

ValueError: time data '' does not match format '%Y-%m-%d %H:%M'

This takes down pybabel entirely when updating or compiling such a file, as reported.

Fix

Treat a blank (or whitespace-only) header value the same as an unset one: return None instead of raising. This matches the existing precedent a few lines up in the same function for the Language header ("if the header's value is an empty string, which is what some tools generate").

Test plan

  • Added test_datetime_parsing_blank_value_returns_none, parametrized over '' and ' '.
  • Reproduced the exact reported crash via read_po() on a .po file with blank PO-Revision-Date/POT-Creation-Date headers, confirmed it's gone after the fix (both attributes become None).
  • pytest tests/messages/test_catalog.py — 21 passed (up from 19), same 25 pre-existing failures unrelated to this change (missing CLDR data files in this source checkout — RuntimeError: The babel data files are not available, identical failure list with and without this fix).
  • ruff check / ruff format --check clean on the changed lines.

Fixes python-babel#1219. Some tools (e.g. Poedit) leave these headers blank
instead of eliding them or using the 'YEAR-MO-DA HO:MI+ZONE'
placeholder. _parse_datetime_header() passed the blank value straight
to datetime.strptime(), raising ValueError('time data '' does not
match format...') and crashing pybabel on any such file, as reported.

Treat a blank (or whitespace-only) value the same as an unset header:
return None, matching the existing precedent a few lines up for the
Language header ('if the header's value is an empty string, which is
what some tools generate').
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception raised if the revision date is blank

1 participant