From e26ff11eca0bf56c6d75b9082e7029aefb66b762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 8 Oct 2024 11:04:55 +0200 Subject: [PATCH 1/2] fix(component): avoid crash on getting unused enforcements Fixes #12701 --- weblate/trans/models/component.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/weblate/trans/models/component.py b/weblate/trans/models/component.py index cf009444f018..8be4a614012c 100644 --- a/weblate/trans/models/component.py +++ b/weblate/trans/models/component.py @@ -106,10 +106,12 @@ from weblate.vcs.ssh import add_host_key if TYPE_CHECKING: + from collections.abc import Iterable from datetime import datetime from weblate.addons.models import Addon from weblate.auth.models import AuthenticatedHttpRequest, User + from weblate.checks.base import BaseCheck from weblate.trans.models import Unit NEW_LANG_CHOICES = ( @@ -3747,7 +3749,7 @@ def _schedule_sync_terminology(self) -> None: for glossary in self.project.glossaries: sync_glossary_languages.delay(glossary.pk) - def get_unused_enforcements(self): + def get_unused_enforcements(self) -> Iterable[dict | BaseCheck]: from weblate.trans.models import Unit for current in self.enforced_checks: @@ -3755,6 +3757,7 @@ def get_unused_enforcements(self): check = CHECKS[current] except KeyError: yield {"name": current, "notsupported": True} + continue # Check is always enabled if not check.default_disabled: continue From b264d2f805abbc85efb8e53cf73e21fb06665f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 8 Oct 2024 11:41:16 +0200 Subject: [PATCH 2/2] fix(add-ons): perform post-update with repository lock held It is typically updating the files so avoid possible concurrency with other repository operations. Fixes #12692 --- weblate/addons/base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/weblate/addons/base.py b/weblate/addons/base.py index 0cd24fb954a9..0020b3808e1f 100644 --- a/weblate/addons/base.py +++ b/weblate/addons/base.py @@ -437,9 +437,10 @@ def post_update( self, component: Component, previous_head: str, skip_push: bool ) -> None: # Ignore file parse error, it will be properly tracked as an alert - with suppress(FileParseError): - self.update_translations(component, previous_head) - self.commit_and_push(component, skip_push=skip_push) + with component.repository.lock: + with suppress(FileParseError): + self.update_translations(component, previous_head) + self.commit_and_push(component, skip_push=skip_push) class StoreBaseAddon(BaseAddon):