Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
report: Use ZULIP_VERSION rather than shelling out to git every time.
Alex Vandiver73631950a5cd
diff --git a/zerver/tests/test_report.py b/zerver/tests/test_report.pyindex d026706c3a6..02c9144bc3e 100644--- a/zerver/tests/test_report.py+++ b/zerver/tests/test_report.py@@ -1,4 +1,3 @@-import subprocessfrom typing import Callable, ContextManager, Dict, List, Tuplefrom unittest import mock@@ -151,11 +150,8 @@ class TestReport(ZulipTestCase):))- subprocess_mock = mock.patch(- "zerver.views.report.subprocess.check_output",- side_effect=subprocess.CalledProcessError(1, []),- )- with mock_queue_publish("zerver.views.report.queue_json_publish") as m, subprocess_mock:+ version_mock = mock.patch("zerver.views.report.ZULIP_VERSION", spec="1.2.3")+ with mock_queue_publish("zerver.views.report.queue_json_publish") as m, version_mock:result = self.client_post("/json/report/error", params)self.assert_json_success(result)@@ -168,7 +164,7 @@ class TestReport(ZulipTestCase):# Test with no more_infodel params["more_info"]- with mock_queue_publish("zerver.views.report.queue_json_publish") as m, subprocess_mock:+ with mock_queue_publish("zerver.views.report.queue_json_publish") as m, version_mock:result = self.client_post("/json/report/error", params)self.assert_json_success(result)@@ -181,7 +177,7 @@ class TestReport(ZulipTestCase):# js_source_map actually gets instantiated.with self.settings(DEVELOPMENT=False, TEST_SUITE=False), mock.patch("zerver.lib.unminify.SourceMap.annotate_stacktrace"- ) as annotate, self.assertLogs(level="INFO") as info_logs:+ ) as annotate, self.assertLogs(level="INFO") as info_logs, version_mock:result = self.client_post("/json/report/error", params)self.assert_json_success(result)# fix_params (see above) adds quotes when JSON encoding.diff --git a/zerver/views/report.py b/zerver/views/report.pyindex 9a1640ab13d..b12c53f59cb 100644--- a/zerver/views/report.py+++ b/zerver/views/report.py@@ -1,6 +1,5 @@# System documented in https://zulip.readthedocs.io/en/latest/subsystems/logging.htmlimport logging-import subprocessfrom typing import Any, Mapping, Optional, Unionfrom urllib.parse import SplitResult@@ -10,6 +9,7 @@ from django.http import HttpRequest, HttpResponsefrom django.views.decorators.csrf import csrf_exemptfrom django.views.decorators.http import require_POST+from version import ZULIP_VERSIONfrom zerver.context_processors import get_valid_realm_from_requestfrom zerver.decorator import human_users_onlyfrom zerver.lib.markdown import privacy_clean_markdown@@ -139,13 +139,7 @@ def report_error(if js_source_map:stacktrace = js_source_map.annotate_stacktrace(stacktrace)- try:- version: Optional[str] = subprocess.check_output(- ["git", "show", "-s", "--oneline"],- text=True,- )- except (FileNotFoundError, subprocess.CalledProcessError):- version = None+ version = str(ZULIP_VERSION)# Get the IP address of the requestremote_ip = request.META["REMOTE_ADDR"]