Skip to content

Add the title translation for the email that reports failed queries #30

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

Open
wants to merge 2 commits into
base: epic/ui-translation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions redash/locales/messages.pot
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Translations template for PROJECT.
# Copyright (C) 2024 ORGANIZATION
# Copyright (C) 2025 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2024.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-12-11 16:26+0100\n"
"POT-Creation-Date: 2025-01-08 14:52+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -231,6 +231,10 @@ msgid ""
"for you."
msgstr ""

#: redash/tasks/failure_report.py:59
msgid "Redash failed to execute {count} of your scheduled queries"
msgstr ""

#: redash/templates/error.html:5
msgid "Error"
msgstr ""
Expand Down
6 changes: 5 additions & 1 deletion redash/tasks/failure_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import re
from collections import Counter

from flask_babel import _

from redash import models, redis_connection, settings
from redash.tasks.general import send_mail
from redash.utils import base_url, json_dumps, json_loads, render_template
Expand Down Expand Up @@ -54,7 +56,9 @@ def send_failure_report(user_id):
"base_url": base_url(user.org),
}

subject = f"Redash failed to execute {len(unique_errors.keys())} of your scheduled queries"
subject = _("Redash failed to execute {count} of your scheduled queries").format(
count=len(unique_errors.keys())
)
html, text = [
render_template("emails/failures.{}".format(f), context)
for f in ["html", "txt"]
Expand Down
6 changes: 5 additions & 1 deletion redash/translations/de/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Redash 10.0.0\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-12-11 16:26+0100\n"
"POT-Creation-Date: 2025-01-08 14:52+0100\n"
"PO-Revision-Date: 2024-12-04 15:21+0100\n"
"Last-Translator: metr Building Management Systems team "
"<[email protected]>\n"
Expand Down Expand Up @@ -255,6 +255,10 @@ msgstr ""
"Sie können Ihr eigenes Konto nicht deaktivieren. Bitte bitten Sie einen "
"anderen Administrator, dies für Sie zu tun."

#: redash/tasks/failure_report.py:59
msgid "Redash failed to execute {count} of your scheduled queries"
msgstr "Redash konnte {count} Ihrer geplanten Abfragen nicht ausführen."

#: redash/templates/error.html:5
msgid "Error"
msgstr "Fehler"
Expand Down
12 changes: 8 additions & 4 deletions tests/tasks/test_failure_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ def test_does_not_report_if_query_owner_is_disabled(self):
email_pending = redis_connection.exists(key)
self.assertFalse(email_pending)

def test_does_not_indicate_when_not_near_limit_for_a_query(self):
@mock.patch("redash.tasks.failure_report._", side_effect=lambda x: x)
def test_does_not_indicate_when_not_near_limit_for_a_query(self, mock_translation):
self.notify(schedule_failures=settings.MAX_FAILURE_REPORTS_PER_QUERY / 2)
failures = self.send_email(self.factory.user)

self.assertFalse(failures[0]["comment"])

def test_indicates_when_near_limit_for_a_query(self):
@mock.patch("redash.tasks.failure_report._", side_effect=lambda x: x)
def test_indicates_when_near_limit_for_a_query(self, mock_translation):
self.notify(schedule_failures=settings.MAX_FAILURE_REPORTS_PER_QUERY - 1)
failures = self.send_email(self.factory.user)

Expand All @@ -71,7 +73,8 @@ def test_aggregates_different_queries_in_a_single_report(self):

self.assertEqual(key1, key2)

def test_counts_failures_for_each_reason(self):
@mock.patch("redash.tasks.failure_report._", side_effect=lambda x: x)
def test_counts_failures_for_each_reason(self, mock_translation):
query = self.factory.create_query()

self.notify(message="I'm a failure", query=query)
Expand All @@ -88,7 +91,8 @@ def test_counts_failures_for_each_reason(self):
f3 = next(f for f in failures if f["failure_reason"] == "I'm a totally different query")
self.assertEqual(1, f3["failure_count"])

def test_shows_latest_failure_time(self):
@mock.patch("redash.tasks.failure_report._", side_effect=lambda x: x)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why we need this patch here. If the user doesn't have the translation configured, won't flask_babel already return the same string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it some time, I don't know why it fails finding the correct translation files... which does not happen when running the class test separately, I tried few things ... I could not manage to make it work yet but will keep it aside and return to it later

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's a missing configuration when running the tests. When you come to it later you can look over a way to set the directory manually when running the tests by changing the conftest.py

def test_shows_latest_failure_time(self, mock_translation):
query = self.factory.create_query()

with freeze_time("2000-01-01"):
Expand Down