From e885656e2af8b944bc908a22399c394c90ce209c Mon Sep 17 00:00:00 2001
From: Li Liu
Date: Thu, 14 Dec 2023 20:05:21 +0800
Subject: [PATCH] Deprecate Invalid config checking
Signed-off-by: Li Liu
---
src/common/config.cc | 31 ++++++++++++++++---------------
tests/ut/test_config.cc | 14 +++++++++++---
2 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/src/common/config.cc b/src/common/config.cc
index f54c705a3..45eaea9b5 100644
--- a/src/common/config.cc
+++ b/src/common/config.cc
@@ -53,21 +53,22 @@ static const std::unordered_set ext_legal_json_keys = {"metric_type
Status
Config::FormatAndCheck(const Config& cfg, Json& json, std::string* const err_msg) {
- try {
- for (auto& it : json.items()) {
- // valid only if it.key() exists in one of cfg.__DICT__ and ext_legal_json_keys
- if (cfg.__DICT__.find(it.key()) == cfg.__DICT__.end() &&
- ext_legal_json_keys.find(it.key()) == ext_legal_json_keys.end()) {
- throw KnowhereException(std::string("invalid json key ") + it.key());
- }
- }
- } catch (std::exception& e) {
- LOG_KNOWHERE_ERROR_ << e.what();
- if (err_msg) {
- *err_msg = e.what();
- }
- return Status::invalid_param_in_json;
- }
+ // Deprecated invalid json key check for now
+ // try {
+ // for (auto& it : json.items()) {
+ // // valid only if it.key() exists in one of cfg.__DICT__ and ext_legal_json_keys
+ // if (cfg.__DICT__.find(it.key()) == cfg.__DICT__.end() &&
+ // ext_legal_json_keys.find(it.key()) == ext_legal_json_keys.end()) {
+ // throw KnowhereException(std::string("invalid json key ") + it.key());
+ // }
+ // }
+ // } catch (std::exception& e) {
+ // LOG_KNOWHERE_ERROR_ << e.what();
+ // if (err_msg) {
+ // *err_msg = e.what();
+ // }
+ // return Status::invalid_param_in_json;
+ // }
try {
for (const auto& it : cfg.__DICT__) {
diff --git a/tests/ut/test_config.cc b/tests/ut/test_config.cc
index c6b9181d3..73e688ab5 100644
--- a/tests/ut/test_config.cc
+++ b/tests/ut/test_config.cc
@@ -44,14 +44,22 @@ TEST_CASE("Test config json parse", "[config]") {
})",
R"({
"12-s": 19878
- })",
+ })");
+ knowhere::BaseConfig test_config;
+ knowhere::Json test_json = knowhere::Json::parse(invalid_json_str);
+ s = knowhere::Config::FormatAndCheck(test_config, test_json);
+ CHECK(s == knowhere::Status::success);
+ }
+
+ SECTION("check invalid json values") {
+ auto invalid_json_str = GENERATE(as{},
R"({
"k": "100.12"
})");
knowhere::BaseConfig test_config;
knowhere::Json test_json = knowhere::Json::parse(invalid_json_str);
s = knowhere::Config::FormatAndCheck(test_config, test_json);
- CHECK(s != knowhere::Status::success);
+ CHECK(s == knowhere::Status::invalid_value_in_json);
}
SECTION("Check the json for the specific index") {
@@ -83,7 +91,7 @@ TEST_CASE("Test config json parse", "[config]") {
})");
knowhere::HnswConfig hnsw_config;
s = knowhere::Config::FormatAndCheck(hnsw_config, large_build_json);
- CHECK(s == knowhere::Status::invalid_param_in_json);
+ CHECK(s == knowhere::Status::success);
knowhere::DiskANNConfig diskann_config;
s = knowhere::Config::FormatAndCheck(diskann_config, large_build_json);
CHECK(s == knowhere::Status::success);