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

Cache key collision in render checks for suggestions #12673

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions weblate/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ def get_fixup(self, unit: Unit) -> Iterable[tuple[str, str, str]] | None:
def render(self, request: AuthenticatedHttpRequest, unit: Unit) -> StrOrPromise:
raise Http404("Not supported")

def get_cache_key(self, unit: Unit, pos: int) -> str:
return "check:{}:{}:{}:{}".format(
def get_cache_key(
self, unit: Unit, pos: int, fake_discriminator: int | None = None
) -> str:
vinceh121 marked this conversation as resolved.
Show resolved Hide resolved
return "check:{}:{}:{}:{}:{}".format(
self.check_id,
unit.pk,
siphash("Weblate Checks", unit.all_flags.format()),
pos,
unit.suggestion_id if hasattr(unit, "suggestion_id") else "",
)

def get_replacement_function(self, unit: Unit):
Expand Down
1 change: 1 addition & 0 deletions weblate/trans/models/suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
fake_unit = copy(self.unit)
fake_unit.target = self.target
fake_unit.state = STATE_TRANSLATED
fake_unit.suggestion_id = self.pk

Check warning on line 227 in weblate/trans/models/suggestion.py

View check run for this annotation

Codecov / codecov/patch

weblate/trans/models/suggestion.py#L227

Added line #L227 was not covered by tests
vinceh121 marked this conversation as resolved.
Show resolved Hide resolved
source = fake_unit.get_source_plurals()
target = fake_unit.get_target_plurals()

Expand Down
Loading