Skip to content

Don't crash on blank PO-Revision-Date/POT-Creation-Date headers - #1311

Open
vjymisal0 wants to merge 1 commit into
python-babel:masterfrom
vjymisal0:fix-blank-po-date-headers
Open

Don't crash on blank PO-Revision-Date/POT-Creation-Date headers#1311
vjymisal0 wants to merge 1 commit into
python-babel:masterfrom
vjymisal0:fix-blank-po-date-headers

Conversation

@vjymisal0

Copy link
Copy Markdown

Bug

Closes #1219

Some tools (e.g. Poedit) leave PO-Revision-Date or POT-Creation-Date blank in a .po file's header, instead of using the YEAR-MO-DA HO:MI+ZONE placeholder or omitting the header entirely.

Catalog._set_mime_headers() passes that value straight to _parse_datetime_header(), which does:

dt = datetime.datetime.strptime(match.group('datetime'), '%Y-%m-%d %H:%M')

With an empty string this raises:

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

which propagates all the way up and crashes pybabel extract/update/compile (see the traceback in #1219).

Fix

Wrap both call sites (pot-creation-date and po-revision-date) in contextlib.suppress(ValueError), so a blank or otherwise malformed date header is simply ignored (keeping whatever default/previous value the Catalog already had) instead of aborting the whole command. This matches the "ignore the blank date, or at least give a graceful message instead of crashing" request in the issue.

Testing

  • Added test_catalog_set_mime_headers_ignores_blank_dates in tests/messages/test_catalog.py, which reproduces the crash against the old code (fails with the reported ValueError before the fix) and passes after it.
  • Ran the full test suite: pytest tests/messages — 353 passed.
  • Ran ruff check on the changed files — no issues.

Some tools (e.g. Poedit) leave PO-Revision-Date or POT-Creation-Date
blank instead of using the YEAR-MO-DA placeholder or omitting the
header. Catalog._set_mime_headers() passed the empty string straight
to _parse_datetime_header(), which calls
datetime.strptime('', '%Y-%m-%d %H:%M') and raises ValueError,
crashing pybabel extract/update/compile.

Wrap both call sites in contextlib.suppress(ValueError) so a blank or
otherwise malformed date header is ignored (keeping the previous
value) instead of aborting the whole command.

Fixes python-babel#1219
Copilot AI lite review requested due to automatic review settings August 10, 2026 15:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

2 participants