Skip to content

Commit

Permalink
add-ons: correctly skip not compatible site-wide add-ons
Browse files Browse the repository at this point in the history
Fixes #11476
  • Loading branch information
nijel committed Apr 24, 2024
1 parent 6695e49 commit 61fbc98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions weblate/addons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def execute_addon_event(
with transaction.atomic():
scope.log_debug("running %s add-on: %s", event.label, addon.name)
# Skip unsupported components silently
if addon.component and not addon.addon.can_install(component, None):
if not addon.component and not addon.addon.can_install(component, None):
scope.log_debug(
"Skipping incompatible %s add-on: %s for component: %s",
event.label,
Expand All @@ -272,7 +272,7 @@ def execute_addon_event(
scope.log_error("failed %s add-on: %s: %s", event.label, addon.name, error)
report_error(cause=f"add-on {addon.name} failed", project=component.project)
# Uninstall no longer compatible add-ons
if not addon.addon.can_install(scope, None):
if not addon.addon.can_install(component, None):
scope.log_warning(
"uninstalling incompatible %s add-on: %s", event.label, addon.name
)
Expand Down
19 changes: 19 additions & 0 deletions weblate/addons/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,3 +1430,22 @@ def test_extract_broken(self) -> None:
)
# The error should be there
self.assertTrue(self.component.alert_set.filter(name="CDNAddonError").exists())


class SiteWideAddonsTest(ViewTestCase):
def create_component(self):
return self.create_java()

def test_json(self):
JSONCustomizeAddon.create(
configuration={"indent": 8, "sort": 1, "style": "spaces"},
)
# This is not needed in real life as installation will happen
# in a different request so local caching does not apply
self.component.drop_addons_cache()
rev = self.component.repository.last_revision

self.edit_unit("Hello, world!\n", "Nazdar svete!\n")
self.get_translation().commit_pending("test", None)

self.assertNotEqual(rev, self.component.repository.last_revision)

0 comments on commit 61fbc98

Please sign in to comment.