Skip to content

Commit 81c00a4

Browse files
Merge pull request ClickHouse#18167 from ClickHouse/fix_checking_profile_settings_constraints
Fix `Unknown setting profile` error on attempt to set settings profile
2 parents b159e15 + 76e73e4 commit 81c00a4

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/Access/SettingsConstraints.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,25 @@ bool SettingsConstraints::checkImpl(const Settings & current_settings, SettingCh
156156
{
157157
const String & setting_name = change.name;
158158

159+
if (setting_name == "profile")
160+
{
161+
/// TODO Check profile settings in Context::setProfile(...), not here. It will be backward incompatible.
162+
const String & profile_name = change.value.safeGet<String>();
163+
const auto & profile_settings_changes = manager->getProfileSettings(profile_name);
164+
try
165+
{
166+
/// NOTE We cannot use CLAMP_ON_VIOLATION here, because we cannot modify elements of profile_settings_changes
167+
for (auto change_copy : *profile_settings_changes)
168+
checkImpl(current_settings, change_copy, THROW_ON_VIOLATION);
169+
}
170+
catch (Exception & e)
171+
{
172+
e.addMessage(", while trying to set settings profile {}", profile_name);
173+
throw;
174+
}
175+
return true;
176+
}
177+
159178
bool cannot_cast;
160179
auto cast_value = [&](const Field & x) -> Field
161180
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
0 0
2+
0 0
3+
OK
4+
1 1
5+
2 1
6+
2 1
7+
OK
8+
1 1
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
. "$CURDIR"/../shell_config.sh
5+
6+
$CLICKHOUSE_CLIENT -n -m -q "select value, changed from system.settings where name='readonly';"
7+
$CLICKHOUSE_CLIENT -n -m -q "set profile='default'; select value, changed from system.settings where name='readonly';"
8+
$CLICKHOUSE_CLIENT -n -m -q "set profile='readonly'; select value, changed from system.settings where name='readonly';" 2>&1| grep -Fa "Cannot modify 'send_logs_level' setting in readonly mode" > /dev/null && echo "OK"
9+
CLICKHOUSE_CLIENT=$(echo ${CLICKHOUSE_CLIENT} | sed 's/'"--send_logs_level=${CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL}"'/--send_logs_level=fatal/g')
10+
$CLICKHOUSE_CLIENT -n -m -q "set profile='readonly'; select value, changed from system.settings where name='readonly';"
11+
12+
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&query=select+value,changed+from+system.settings+where+name='readonly'"
13+
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&profile=default&query=select+value,changed+from+system.settings+where+name='readonly'"
14+
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&profile=readonly&query=select+value,changed+from+system.settings+where+name='readonly'" 2>&1| grep -Fa "Cannot modify 'readonly' setting in readonly mode" > /dev/null && echo "OK"
15+
echo "select value, changed from system.settings where name='readonly';" | ${CLICKHOUSE_CURL} -sSg "${CLICKHOUSE_URL}&profile=readonly" -d @-

0 commit comments

Comments
 (0)