Merge ~cjwatson/launchpad:fix-translations-opening-unapprove into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: bd76d6dbe1aeb025c95445045b2a73774edd5e82
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-translations-opening-unapprove
Merge into: launchpad:master
Diff against target: 49 lines (+19/-1)
1 file modified
scripts/fix-translations-opening.py (+19/-1)
Reviewer Review Type Date Requested Status
William Grant code Approve
Ines Almeida Approve
Review via email: mp+442642@code.launchpad.net

Commit message

fix-translations-opening: Unapprove existing imports

Description of the change

`scripts/fix-translations-opening.py` is run manually in the case where opening translations for a new series is interrupted (usually due to long transactions making it difficult to continue) and leaves translations in an incomplete state.

The last time we did this, in September 2016, we found that we additionally had to set the associated translation import queue entries back from Approved to Needs Review so that `cronscripts/rosetta-approve-imports.py` could process them again (see https://pastebin.canonical.com/164459/). Rather than keeping this solely in folk memory, let's make the `fix-translations-opening` script do that as well.

I'm afraid I don't have a good way to test this short of the real-world run that we're going to need to perform shortly.

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Looks good to me

review: Approve
Revision history for this message
William Grant (wgrant) wrote :

Could I convince you to use the enums rather than hardcoding their integer values? That's a big potential footgun and grep-breaker otherwise.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/fix-translations-opening.py b/scripts/fix-translations-opening.py
2index ad30977..10a9741 100755
3--- a/scripts/fix-translations-opening.py
4+++ b/scripts/fix-translations-opening.py
5@@ -1,6 +1,6 @@
6 #!/usr/bin/python3 -S
7 #
8-# Copyright 2012-2013 Canonical Ltd. This software is licensed under the
9+# Copyright 2012-2023 Canonical Ltd. This software is licensed under the
10 # GNU Affero General Public License version 3 (see the file LICENSE).
11
12 import _pythonpath # noqa: F401
13@@ -13,6 +13,7 @@ from lp.registry.model.distroseries import DistroSeries
14 from lp.services.database.interfaces import IPrimaryStore
15 from lp.services.looptuner import DBLoopTuner, ITunableLoop
16 from lp.services.scripts.base import LaunchpadScript
17+from lp.translations.enums import RosettaImportStatus
18
19 delete_pofiletranslator = """\
20 DELETE FROM POFileTranslator
21@@ -87,6 +88,22 @@ DELETE FROM POTemplate
22 LIMIT ?)
23 """
24
25+# Reset status from Approved to Needs Review; we've just unset the target,
26+# so these entries will have to be gardened again.
27+unapprove_translationimportqueueentry = """\
28+UPDATE TranslationImportQueueEntry
29+ SET status = %(needs_review)d
30+ WHERE TranslationImportQueueEntry.id IN (
31+ SELECT TranslationImportQueueEntry.id
32+ FROM TranslationImportQueueEntry
33+ WHERE TranslationImportQueueEntry.status = %(approved)d
34+ AND TranslationImportQueueEntry.distroseries = ?
35+ LIMIT ?)
36+""" % {
37+ "needs_review": RosettaImportStatus.NEEDS_REVIEW.value,
38+ "approved": RosettaImportStatus.APPROVED.value,
39+}
40+
41 statements = [
42 delete_pofiletranslator,
43 null_translationimportqueueentry_pofile,
44@@ -95,6 +112,7 @@ statements = [
45 delete_packagingjob,
46 null_translationimportqueueentry_potemplate,
47 delete_potemplate,
48+ unapprove_translationimportqueueentry,
49 ]
50
51

Subscribers

People subscribed via source and target branches

to status/vote changes: