fix: prevent Hebrew locale from corrupting subsequent locale formatting#1287
Open
C1-BA-B1-F3 wants to merge 1 commit into
Open
fix: prevent Hebrew locale from corrupting subsequent locale formatting#1287C1-BA-B1-F3 wants to merge 1 commit into
C1-BA-B1-F3 wants to merge 1 commit into
Conversation
Fixes python-babel#1234 The bug: After using Hebrew locale ('he'), subsequent calls to format_date() with other locales (like 'no', 'fr', 'es') returned Hebrew-formatted text instead of the requested locale. Root cause: LocaleDataDict.__getitem__ was mutating the cached locale data when resolving aliases. Hebrew locale's months.stand-alone dict was the same object as root's months.stand-alone dict (due to shallow copying in merge()). When the alias at months.stand-alone.wide was resolved for Hebrew, the resolved Hebrew month names were written back into the shared dict, corrupting the root locale data that all other locales inherit from. Fix: Remove the write-back in LocaleDataDict.__getitem__. The resolved values are no longer stored back into the original data dict, preventing mutation of shared/cached locale data. Added regression tests: - test_locale_data_isolation_hebrew: Verifies month names are not corrupted - test_locale_data_isolation_format_date: Verifies format_date output - test_locale_data_cache_not_mutated: Verifies root data integrity
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.
Summary
Fixes #1234
After using Hebrew locale (), subsequent calls to with other locales (like , , ) returned Hebrew-formatted text instead of the requested locale.
Root Cause
was mutating the cached locale data when resolving aliases. Hebrew locale's dict was the same object as root's dict (due to shallow copying in ). When the alias at was resolved for Hebrew, the resolved Hebrew month names were written back into the shared dict, corrupting the root locale data that all other locales inherit from.
Reproduction
Fix
Remove the write-back in . The resolved values are no longer stored back into the original data dict, preventing mutation of shared/cached locale data.
Tests Added
test_locale_data_isolation_hebrew: Verifies month names are not corrupted after Hebrew usagetest_locale_data_isolation_format_date: Verifies format_date output is correct after Hebrewtest_locale_data_cache_not_mutated: Verifies root data integrity after alias resolutionAll 7325 existing tests pass with this change.