diff --git a/src/Access/SettingsConstraints.cpp b/src/Access/SettingsConstraints.cpp index c9a6b6f6b7a..7dce4d96b33 100644 --- a/src/Access/SettingsConstraints.cpp +++ b/src/Access/SettingsConstraints.cpp @@ -156,6 +156,25 @@ bool SettingsConstraints::checkImpl(const Settings & current_settings, SettingCh { const String & setting_name = change.name; + if (setting_name == "profile") + { + /// TODO Check profile settings in Context::setProfile(...), not here. It will be backward incompatible. + const String & profile_name = change.value.safeGet(); + const auto & profile_settings_changes = manager->getProfileSettings(profile_name); + try + { + /// NOTE We cannot use CLAMP_ON_VIOLATION here, because we cannot modify elements of profile_settings_changes + for (auto change_copy : *profile_settings_changes) + checkImpl(current_settings, change_copy, THROW_ON_VIOLATION); + } + catch (Exception & e) + { + e.addMessage(", while trying to set settings profile {}", profile_name); + throw; + } + return true; + } + bool cannot_cast; auto cast_value = [&](const Field & x) -> Field { diff --git a/tests/queries/0_stateless/01187_set_profile_as_setting.reference b/tests/queries/0_stateless/01187_set_profile_as_setting.reference new file mode 100644 index 00000000000..ae1cc97819b --- /dev/null +++ b/tests/queries/0_stateless/01187_set_profile_as_setting.reference @@ -0,0 +1,8 @@ +0 0 +0 0 +OK +1 1 +2 1 +2 1 +OK +1 1 diff --git a/tests/queries/0_stateless/01187_set_profile_as_setting.sh b/tests/queries/0_stateless/01187_set_profile_as_setting.sh new file mode 100755 index 00000000000..8247ab8870a --- /dev/null +++ b/tests/queries/0_stateless/01187_set_profile_as_setting.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. "$CURDIR"/../shell_config.sh + +$CLICKHOUSE_CLIENT -n -m -q "select value, changed from system.settings where name='readonly';" +$CLICKHOUSE_CLIENT -n -m -q "set profile='default'; select value, changed from system.settings where name='readonly';" +$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" +CLICKHOUSE_CLIENT=$(echo ${CLICKHOUSE_CLIENT} | sed 's/'"--send_logs_level=${CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL}"'/--send_logs_level=fatal/g') +$CLICKHOUSE_CLIENT -n -m -q "set profile='readonly'; select value, changed from system.settings where name='readonly';" + +${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&query=select+value,changed+from+system.settings+where+name='readonly'" +${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&profile=default&query=select+value,changed+from+system.settings+where+name='readonly'" +${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" +echo "select value, changed from system.settings where name='readonly';" | ${CLICKHOUSE_CURL} -sSg "${CLICKHOUSE_URL}&profile=readonly" -d @-