Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsoletes with same ID from different contexts get removed on update #1124

Open
LeXofLeviafan opened this issue Sep 11, 2024 · 1 comment · May be fixed by #1132
Open

Obsoletes with same ID from different contexts get removed on update #1124

LeXofLeviafan opened this issue Sep 11, 2024 · 1 comment · May be fixed by #1132

Comments

@LeXofLeviafan
Copy link

Overview Description

When a file contains multiple obsoletes from different contexts, and they have the same ID, all but the last one will get stripped from the file.

Steps to Reproduce

  1. Place multiple messages into a PO file with same msgid but different msgctxt (in arbitrary order, optionally including one without a msgctxt as well):
    msgctxt "context1"
    msgid "foo"
    msgstr "foo-1"
    
    msgid "foo"
    msgstr "foo-0"
    
    msgctxt "context2"
    msgid "foo"
    msgstr "foo-2"
  2. Run pybabel update with appropriate params; the messages should be moved to the end of the file and marked obsolete:
    #~ msgctxt "context1"
    #~ msgid "foo"
    #~ msgstr "foo-1"
    
    #~ msgid "foo"
    #~ msgstr "foo-0"
    
    #~ msgctxt "context2"
    #~ msgid "foo"
    #~ msgstr "foo-2"
  3. Re-run the previous command

Actual Results

Only the last obsolete entry with that msgid remains in the file (based on their order before the last update command, and regardless of whether a message without msgctxt was present):

#~ msgctxt "context2"
#~ msgid "foo"
#~ msgstr "foo-2"

Expected Results

The messages were from different contexts so they should all be retained.

Reproducibility

This issue appears to reproduce whenever the described situation occurs.

Additional Information

Tested on Babel version 2.16.0

@tomasr8
Copy link
Member

tomasr8 commented Sep 16, 2024

Seems to be an issue with how the obsolete mesages are parsed:

if self.obsolete:
if not self.ignore_obsolete:
self.catalog.obsolete[msgid] = message

The above looks to only be using the msgid, rather than (msgid, msgctx), so messages with the same msgid but different msgctx will get overwritten. This seems to fix it:

if self.obsolete:
    if not self.ignore_obsolete:
-        self.catalog.obsolete[msgid] = message
+        self.catalog.obsolete[self.catalog._key_for(msgid, msgctxt)] = message

@tomasr8 tomasr8 linked a pull request Sep 23, 2024 that will close this issue
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 a pull request may close this issue.

2 participants