Merge pull request #44411 from thevar1able/fix-settings-constraints

Fix settings constraints
This commit is contained in:
Konstantin Bogdanov 2022-12-20 10:19:07 +01:00 committed by GitHub
commit 93375fc3e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 1 deletions

View File

@ -75,6 +75,10 @@ void SettingsProfileElement::init(const ASTSettingsProfileElement & ast, const A
}
}
bool SettingsProfileElement::isConstraint() const
{
return this->writability || !this->min_value.isNull() || !this->max_value.isNull();
}
std::shared_ptr<ASTSettingsProfileElement> SettingsProfileElement::toAST() const
{
@ -213,7 +217,7 @@ SettingsConstraints SettingsProfileElements::toSettingsConstraints(const AccessC
{
SettingsConstraints res{access_control};
for (const auto & elem : *this)
if (!elem.setting_name.empty() && elem.setting_name != ALLOW_BACKUP_SETTING_NAME)
if (!elem.setting_name.empty() && elem.isConstraint() && elem.setting_name != ALLOW_BACKUP_SETTING_NAME)
res.set(
elem.setting_name,
elem.min_value,

View File

@ -44,6 +44,8 @@ struct SettingsProfileElement
std::shared_ptr<ASTSettingsProfileElement> toAST() const;
std::shared_ptr<ASTSettingsProfileElement> toASTWithNames(const AccessControl & access_control) const;
bool isConstraint() const;
private:
void init(const ASTSettingsProfileElement & ast, const AccessControl * access_control);
};

View File

@ -0,0 +1,22 @@
<clickhouse>
<profiles>
<default>
<constraints>
<log_queries>
<readonly>1</readonly>
</log_queries>
</constraints>
<log_queries>1</log_queries>
</default>
</profiles>
<users>
<test_profile_settings_and_constraints_order>
<password></password>
<networks>
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</test_profile_settings_and_constraints_order>
</users>
</clickhouse>

View File

@ -0,0 +1,22 @@
<clickhouse>
<profiles>
<default>
<log_queries>1</log_queries>
<constraints>
<log_queries>
<readonly>1</readonly>
</log_queries>
</constraints>
</default>
</profiles>
<users>
<test_profile_settings_and_constraints_order>
<password/>
<networks>
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</test_profile_settings_and_constraints_order>
</users>
</clickhouse>

View File

@ -0,0 +1,40 @@
import pytest
from helpers.client import QueryRuntimeException
from helpers.cluster import ClickHouseCluster
from helpers.test_tools import TSV
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance("node1", user_configs=["configs/constraints_first.xml"])
node2 = cluster.add_instance("node2", user_configs=["configs/constraints_last.xml"])
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_profile_settings_and_constraints_order(started_cluster):
query = "SELECT name, readonly FROM system.settings WHERE name == 'log_queries'"
expected = """\
log_queries 1"""
settings = node1.query(
query,
user="test_profile_settings_and_constraints_order",
)
assert TSV(settings) == TSV(expected)
settings = node2.query(
query,
user="test_profile_settings_and_constraints_order",
)
assert TSV(settings) == TSV(expected)