Don't crash on blank PO-Revision-Date/POT-Creation-Date headers - #1311
Open
vjymisal0 wants to merge 1 commit into
Open
Don't crash on blank PO-Revision-Date/POT-Creation-Date headers#1311vjymisal0 wants to merge 1 commit into
vjymisal0 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Closes #1219
Some tools (e.g. Poedit) leave
PO-Revision-DateorPOT-Creation-Dateblank in a.pofile's header, instead of using theYEAR-MO-DA HO:MI+ZONEplaceholder or omitting the header entirely.Catalog._set_mime_headers()passes that value straight to_parse_datetime_header(), which does:With an empty string this raises:
which propagates all the way up and crashes
pybabel extract/update/compile(see the traceback in #1219).Fix
Wrap both call sites (
pot-creation-dateandpo-revision-date) incontextlib.suppress(ValueError), so a blank or otherwise malformed date header is simply ignored (keeping whatever default/previous value theCatalogalready 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
test_catalog_set_mime_headers_ignores_blank_datesintests/messages/test_catalog.py, which reproduces the crash against the old code (fails with the reportedValueErrorbefore the fix) and passes after it.pytest tests/messages— 353 passed.ruff checkon the changed files — no issues.