Skip to content

fix(localedata): don't memoize resolved aliases into shared parent data#1274

Open
SAY-5 wants to merge 1 commit into
python-babel:masterfrom
SAY-5:fix-1234-alias-shared-data
Open

fix(localedata): don't memoize resolved aliases into shared parent data#1274
SAY-5 wants to merge 1 commit into
python-babel:masterfrom
SAY-5:fix-1234-alias-shared-data

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 24, 2026

Fixes #1234.

A locale that inherits an entire nested sub-dict from its parent shares the same dict object (merge only copies keys present in the child's own data). When LocaleDataDict.__getitem__ resolved an Alias and wrote the resolved value back into self._data as a memoization, it mutated that shared dict, corrupting the parent locale (and every sibling that inherits it).

For example he aliases its stand-alone wide months to the Hebrew format months. After format_date(d, 'LLLL', 'he'), a later format_date(d, 'LLLL', 'de') returned Hebrew text because root's shared months/stand-alone/wide Alias had been overwritten.

Fix: skip the write-back memoization when the value came from resolving an alias, since the backing dict may be shared with a parent locale. Plain nested dicts are still wrapped and memoized as before.

Added a regression test.

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.

Hebrew Locale Corrupts Subsequent Locale Formatting

1 participant