Skip to content

Commit f9a8022

Browse files
authored
Merge branch 'master' into patch-1
2 parents 3949398 + 43ee21a commit f9a8022

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

redash/destinations/webhook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def notify(self, alert, query, user, new_state, app, host, metadata, options):
4242
auth = HTTPBasicAuth(options.get("username"), options.get("password")) if options.get("username") else None
4343
resp = requests.post(
4444
options.get("url"),
45-
data=json_dumps(data),
45+
data=json_dumps(data).encode("utf-8"),
4646
auth=auth,
4747
headers=headers,
4848
timeout=5.0,

redash/tasks/queries/maintenance.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
QueryDetachedFromDataSourceError,
1010
)
1111
from redash.monitor import rq_job_ids
12+
from redash.query_runner import NotSupported
1213
from redash.tasks.failure_report import track_failure
1314
from redash.utils import json_dumps, sentry
1415
from redash.worker import get_job_logger, job
@@ -177,6 +178,8 @@ def refresh_schema(data_source_id):
177178
time.time() - start_time,
178179
)
179180
statsd_client.incr("refresh_schema.timeout")
181+
except NotSupported:
182+
logger.debug("Datasource %s does not support schema refresh", ds.name)
180183
except Exception:
181184
logger.warning("Failed refreshing schema for the data source: %s", ds.name, exc_info=1)
182185
statsd_client.incr("refresh_schema.error")

redash/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def collect_parameters_from_request(args):
211211

212212
def base_url(org):
213213
if settings.MULTI_ORG:
214-
return "https://{}/{}".format(settings.HOST, org.slug)
214+
return "{}/{}".format(settings.HOST, org.slug)
215215

216216
return settings.HOST
217217

tests/destinations/test_webhook.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import json
2+
from unittest import mock
3+
4+
from redash.destinations.webhook import Webhook
5+
from redash.models import Alert
6+
7+
8+
def test_webhook_notify_handles_unicode():
9+
# Create a mock alert with all the properties needed by serialize_alert
10+
alert = mock.Mock()
11+
alert.id = 1
12+
alert.name = "Test Alert"
13+
alert.custom_subject = "Test Subject With Unicode: 晨"
14+
alert.custom_body = "Test Body"
15+
alert.options = {}
16+
alert.state = "ok"
17+
alert.last_triggered_at = None
18+
alert.updated_at = "2025-12-02T08:00:00Z"
19+
alert.created_at = "2025-12-02T08:00:00Z"
20+
alert.rearm = None
21+
alert.query_id = 10
22+
alert.user_id = 20
23+
24+
query = mock.Mock()
25+
user = mock.Mock()
26+
app = mock.Mock()
27+
host = "http://redash.local"
28+
options = {"url": "https://example.com/webhook", "username": "user", "password": "password"}
29+
metadata = {}
30+
new_state = Alert.TRIGGERED_STATE
31+
destination = Webhook(options)
32+
33+
with mock.patch("redash.destinations.webhook.requests.post") as mock_post:
34+
mock_response = mock.Mock()
35+
mock_response.status_code = 200
36+
mock_post.return_value = mock_response
37+
38+
destination.notify(alert, query, user, new_state, app, host, metadata, options)
39+
40+
# Get the data passed to the mock
41+
call_args, call_kwargs = mock_post.call_args
42+
sent_data = call_kwargs["data"]
43+
44+
# 1. Make sure we send bytes
45+
assert isinstance(sent_data, bytes)
46+
47+
# 2. Make sure the bytes are the correct UTF-8 encoded JSON
48+
decoded_data = json.loads(sent_data.decode("utf-8"))
49+
assert decoded_data["alert"]["title"] == alert.custom_subject
50+
assert "Test Subject With Unicode: 晨" in sent_data.decode("utf-8")

tests/models/test_alerts.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import textwrap
22
from unittest import TestCase
33

4+
from redash import settings
45
from redash.models import OPERATORS, Alert, db, next_state
56
from tests import BaseTestCase
67

@@ -176,16 +177,18 @@ def test_render_custom_alert_template(self):
176177
ALERT_CONDITION equals
177178
ALERT_THRESHOLD 5
178179
ALERT_NAME %s
179-
ALERT_URL https:///default/alerts/%d
180+
ALERT_URL %s/default/alerts/%d
180181
QUERY_NAME Query
181-
QUERY_URL https:///default/queries/%d
182+
QUERY_URL %s/default/queries/%d
182183
QUERY_RESULT_VALUE 1
183184
QUERY_RESULT_ROWS [{'foo': 1}]
184185
QUERY_RESULT_COLS [{'name': 'foo', 'type': 'STRING'}]
185186
</pre>
186187
""" % (
187188
alert.name,
189+
settings.HOST,
188190
alert.id,
191+
settings.HOST,
189192
alert.query_id,
190193
)
191194
result = alert.render_template(textwrap.dedent(custom_alert))

0 commit comments

Comments
 (0)