Skip to content

Commit e4f886a

Browse files
committed
fix coderabbit issuse
1 parent 18a9e43 commit e4f886a

8 files changed

Lines changed: 38 additions & 63 deletions

File tree

web/pgadmin/messages.pot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PROJECT VERSION\n"
1010
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
11-
"POT-Creation-Date: 2026-04-01 12:20+0300\n"
11+
"POT-Creation-Date: 2026-04-01 16:57+0300\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -12635,7 +12635,7 @@ msgstr ""
1263512635
#: pgadmin/misc/cloud/static/js/azure.js:34
1263612636
#: pgadmin/misc/cloud/static/js/google.js:35
1263712637
#: pgadmin/static/js/SchemaView/SchemaState/SchemaState.js:158
12638-
#: pgadmin/static/js/components/ReactCodeMirror/index.jsx:222
12638+
#: pgadmin/static/js/components/ReactCodeMirror/index.jsx:218
1263912639
#: pgadmin/static/js/tree/ObjectExplorer/ObjectExplorerFilter.jsx:58
1264012640
#: pgadmin/tools/expl_pgsql/static/js/ExplainPostgreSQL/index.jsx:68
1264112641
#: pgadmin/tools/user_management/static/js/Users.jsx:261
@@ -16120,7 +16120,7 @@ msgstr ""
1612016120

1612116121
#: pgadmin/tools/expl_pgsql/__init__.py:144
1612216122
#: pgadmin/tools/expl_pgsql/__init__.py:196
16123-
msgid "Failed to post data to the Explain Postgresql API"
16123+
msgid "Failed to post data to the Explain PostgreSQL API"
1612416124
msgstr ""
1612516125

1612616126
#: pgadmin/tools/grant_wizard/__init__.py:383

web/pgadmin/static/js/components/ReactCodeMirror/index.jsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,17 @@ export default function CodeMirror({className, currEditor, showCopyBtn=false, cu
101101
}
102102
let formattedSql;
103103
if (explPgsqlPrefs.explain_postgresql_format) {
104-
let loadingTimeout;
104+
let loadingTimeout = setTimeout(() => {
105+
setLoading(true);
106+
}, 500);
105107
try {
106-
loadingTimeout = setTimeout(() => {
107-
setLoading(true);
108-
}, 500);
109108
formattedSql = await explPgsqlFormatSQL(sql);
110109
} catch (e) {
111110
console.error('Error formatting SQL using Explain PostgreSQL API:', e);
112111
formattedSql = format(sql,formatPrefs);
113112
} finally {
114-
if (loading) {
115-
setLoading(false);
116-
} else {
117-
clearTimeout(loadingTimeout);
118-
}
113+
clearTimeout(loadingTimeout);
114+
setLoading(false);
119115
}
120116
} else {
121117
formattedSql = format(sql,formatPrefs);

web/pgadmin/tools/expl_pgsql/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def formatSQL():
141141
return make_json_response(
142142
success=0,
143143
errormsg=data,
144-
info=gettext('Failed to post data to the Explain Postgresql API'),
144+
info=gettext('Failed to post data to the Explain PostgreSQL API'),
145145
)
146146

147147
return make_json_response(success=1, data=data)
@@ -193,7 +193,7 @@ def explain():
193193
return make_json_response(
194194
success=0,
195195
errormsg=response_data,
196-
info=gettext('Failed to post data to the Explain Postgresql API'),
196+
info=gettext('Failed to post data to the Explain PostgreSQL API'),
197197
)
198198

199199
# response_data should be a relative path from 302 Location header
@@ -208,8 +208,7 @@ def explain():
208208

209209
def is_valid_url(url):
210210
"""
211-
Validate that a URL is safe to use
212-
(HTTP/HTTPS only, localhost and private IP ranges are allowed).
211+
Validate that a URL is safe to use (HTTP/HTTPS only).
213212
214213
Args:
215214
url: The URL to validate

web/pgadmin/tools/expl_pgsql/static/js/ExplainPostgreSQL/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ export default function ExplainPostgreSQL({
3939
const api = getApiInstance();
4040
api.post(
4141
url_for('expl_pgsql.explain'),
42-
JSON.stringify({
42+
{
4343
plan: JSON.stringify(plans),
4444
query: sql,
45-
}))
45+
})
4646
.then((res) => {
4747
if (res.data?.success) {
4848
setData(res.data?.data);
@@ -86,7 +86,7 @@ export default function ExplainPostgreSQL({
8686
}
8787

8888
ExplainPostgreSQL.propTypes = {
89-
plans: PropTypes.array.isRequired,
89+
plans: PropTypes.array,
9090
emptyMessage: PropTypes.string,
9191
sql: PropTypes.string,
9292
};

web/pgadmin/tools/expl_pgsql/tests/test_format_sql.py

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ class TestFormatSQLFunctionality(BaseTestGenerator):
3434

3535
def runTest(self):
3636
"""Run test case."""
37+
with patch('pgadmin.tools.expl_pgsql.get_preference_value') as mock_pref, \
38+
patch('pgadmin.tools.expl_pgsql.is_valid_url') as mock_valid, \
39+
patch('pgadmin.tools.expl_pgsql.send_post_request') as mock_send:
40+
41+
mock_pref.return_value = 'https://explain.tensor.ru'
42+
mock_valid.return_value = True
43+
mock_send.return_value = (False, json.dumps({
44+
'btf_query': '<span class=\'sql_keyword\'>SELECT</span>',
45+
'btf_query_text': 'SELECT\\n\\t*\\nFROM\\n\\ttest_table\\nWHERE\\n\\tid = 1;'
46+
}))
47+
3748
if self.expected_success:
3849
response = self.tester.post(
3950
self.url,
@@ -52,39 +63,3 @@ def runTest(self):
5263
self.assertEqual(response.status_code, 200)
5364
response_data = json.loads(response.data.decode('utf-8'))
5465
self.assertFalse(response_data['success'])
55-
56-
57-
if self.method == 'POST':
58-
# Mock the preference values
59-
with patch('pgadmin.tools.expl_pgsql.get_preference_value') as mock_pref:
60-
mock_pref.return_value = 'https://explain.tensor.ru'
61-
62-
# Mock the URL validation
63-
with patch('pgadmin.tools.expl_pgsql.is_valid_url') as mock_valid:
64-
mock_valid.return_value = True
65-
66-
# Mock the HTTP request
67-
with patch('pgadmin.tools.expl_pgsql.send_post_request') as mock_send:
68-
mock_send.return_value = (False, json.dumps({
69-
'btf_query': '<span class=\'sql_keyword\'>SELECT</span>\\n <span class=\'sql_asterisk\'>*</span>\\n<span class=\'sql_keyword\'>FROM</span>\\n <span class=\'sql_relation\'>test_table</span>\\n<span class=\'sql_keyword\'>WHERE</span>\\n <span class=\'sql_column\'>id</span> = <span class=\'sql_const\'>1</span>;',
70-
'btf_query_text': 'SELECT\\n\\t*\\nFROM\\n\\ttest_table\\nWHERE\\n\\tid = 1;'
71-
}))
72-
73-
if self.expected_success:
74-
response = self.tester.post(
75-
self.url,
76-
data=json.dumps(self.data),
77-
content_type='application/json'
78-
)
79-
self.assertEqual(response.status_code, 200)
80-
response_data = json.loads(response.data.decode('utf-8'))
81-
self.assertTrue(response_data['success'])
82-
else:
83-
response = self.tester.post(
84-
self.url,
85-
data=self.data,
86-
content_type='application/json'
87-
)
88-
self.assertEqual(response.status_code, 200)
89-
response_data = json.loads(response.data.decode('utf-8'))
90-
self.assertFalse(response_data['success'])
1.52 KB
Binary file not shown.

web/pgadmin/translations/ru/LC_MESSAGES/messages.po

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: pgAdmin 4\n"
1010
"Report-Msgid-Bugs-To: degit22@gmail.com\n"
11-
"POT-Creation-Date: 2026-04-01 12:20+0300\n"
11+
"POT-Creation-Date: 2026-04-01 16:57+0300\n"
1212
"PO-Revision-Date: 2026-01-02 00:05+0700\n"
1313
"Last-Translator: Degit22 <degit22@gmail.com>\n"
1414
"Language: ru\n"
@@ -12903,7 +12903,7 @@ msgstr ""
1290312903
#: pgadmin/misc/cloud/static/js/azure.js:34
1290412904
#: pgadmin/misc/cloud/static/js/google.js:35
1290512905
#: pgadmin/static/js/SchemaView/SchemaState/SchemaState.js:158
12906-
#: pgadmin/static/js/components/ReactCodeMirror/index.jsx:222
12906+
#: pgadmin/static/js/components/ReactCodeMirror/index.jsx:218
1290712907
#: pgadmin/static/js/tree/ObjectExplorer/ObjectExplorerFilter.jsx:58
1290812908
#: pgadmin/tools/expl_pgsql/static/js/ExplainPostgreSQL/index.jsx:68
1290912909
#: pgadmin/tools/user_management/static/js/Users.jsx:261
@@ -16386,7 +16386,9 @@ msgstr "Адрес API Explain PostgreSQL"
1638616386

1638716387
#: pgadmin/tools/expl_pgsql/__init__.py:48
1638816388
msgid "Explain PostgreSQL API endpoint (e.g. https://explain.tensor.ru)"
16389-
msgstr "Точка доступа к API Explain PostgreSQL (например, https://explain.tensor.ru)"
16389+
msgstr ""
16390+
"Точка доступа к API Explain PostgreSQL (например, "
16391+
"https://explain.tensor.ru)"
1639016392

1639116393
#: pgadmin/tools/expl_pgsql/__init__.py:56
1639216394
msgid "Private Plans"
@@ -16403,23 +16405,23 @@ msgstr "Форматирование SQL с использованием API Exp
1640316405
#: pgadmin/tools/expl_pgsql/__init__.py:118
1640416406
#: pgadmin/tools/expl_pgsql/__init__.py:166
1640516407
msgid "JSON payload must be an object, not null, array, or scalar value"
16406-
msgstr ""
16408+
msgstr "Некорректные данные в JSON, должен быть объект"
1640716409

1640816410
#: pgadmin/tools/expl_pgsql/__init__.py:130
1640916411
#: pgadmin/tools/expl_pgsql/__init__.py:178
1641016412
msgid "Invalid API endpoint URL. Only HTTP/HTTPS URLs are allowed."
16411-
msgstr "Некорретный адрес для точки доступа к API. Используйте HTTP/HTTPS."
16413+
msgstr "Некорректный адрес для точки доступа к API. Используйте HTTP/HTTPS."
1641216414

1641316415
#: pgadmin/tools/expl_pgsql/__init__.py:133
1641416416
#: pgadmin/tools/expl_pgsql/__init__.py:181
1641516417
msgid ""
1641616418
"The provided API endpoint is not valid. Only HTTP/HTTPS URLs are "
1641716419
"permitted."
16418-
msgstr "Некорретный адрес для точки доступа к API. Используйте HTTP/HTTPS."
16420+
msgstr "Некорректный адрес для точки доступа к API. Используйте HTTP/HTTPS."
1641916421

1642016422
#: pgadmin/tools/expl_pgsql/__init__.py:144
1642116423
#: pgadmin/tools/expl_pgsql/__init__.py:196
16422-
msgid "Failed to post data to the Explain Postgresql API"
16424+
msgid "Failed to post data to the Explain PostgreSQL API"
1642316425
msgstr "Не удалось отправить данные в API Explain PostgreSQL"
1642416426

1642516427
#: pgadmin/tools/grant_wizard/__init__.py:383
@@ -20033,3 +20035,6 @@ msgstr ""
2003320035
#~ msgid "Describe the SQL you need..."
2003420036
#~ msgstr ""
2003520037

20038+
#~ msgid "Failed to post data to the Explain Postgresql API"
20039+
#~ msgstr "Не удалось отправить данные в API Explain PostgreSQL"
20040+

web/pgadmin/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def get_binary_path_versions(binary_path: str) -> dict:
383383
try:
384384
# if path doesn't exist raise exception
385385
if not os.path.isdir(binary_path):
386-
current_app.logger.warning('Invalid binary path.' + binary_path)
386+
current_app.logger.warning('Invalid binary path.')
387387
raise FileNotFoundError()
388388
# Get the output of the '--version' command
389389
cmd = subprocess.run(

0 commit comments

Comments
 (0)