Skip to content

Commit c89ca7b

Browse files
committed
add basic openapi test
1 parent d0879fd commit c89ca7b

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

lib/collection/src/operations/verification/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Query {
2828
format!(
2929
"Index required but not found for \"{key}\" of one of the following types: [{possible_schemas_str}]",
3030
),
31-
"Create an index for this key or use a different expression.",
31+
"Create an index for this key or use a different formula expression.",
3232
));
3333
}
3434
}

tests/openapi/test_strictmode.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,47 @@ def search_request(condition_size: int = 2):
13231323
assert not search_fail.ok
13241324

13251325

1326+
def test_strict_mode_formula_expression(collection_name):
1327+
1328+
def query_request():
1329+
expression = {
1330+
"sum": [
1331+
"discount_price",
1332+
"$score",
1333+
]
1334+
}
1335+
1336+
return request_with_validation(
1337+
api='/collections/{collection_name}/points/query',
1338+
method="POST",
1339+
path_params={'collection_name': collection_name},
1340+
body={
1341+
"prefetch": {
1342+
"query": [0.1, 0.2, 0.3, 0.4],
1343+
},
1344+
"query": {
1345+
"formula": expression,
1346+
"defaults": { "discount_price": 0 } # Even with default, it should still be restricted
1347+
}
1348+
}
1349+
)
1350+
# No restriction, query succeeds
1351+
query_ok = query_request()
1352+
assert query_ok.ok
1353+
1354+
set_strict_mode(collection_name, {
1355+
"enabled": True,
1356+
"condition_max_size": 1000000, # Disabled
1357+
"unindexed_filtering_retrieve": False,
1358+
})
1359+
1360+
# Now it should fail
1361+
query_fail = query_request()
1362+
assert not query_fail.ok
1363+
assert "discount_price" in query_fail.json()['status']['error']
1364+
assert "formula expression" in query_fail.json()['status']['error']
1365+
1366+
13261367
def test_strict_mode_read_rate_limiting_small_replenish(collection_name):
13271368
"""
13281369
If our read rate limit capacity is larger, test that when exhausting it
@@ -1418,4 +1459,4 @@ def test_strict_mode_unset_rate_limiting_config(collection_name):
14181459
assert new_strict_mode_config['enabled']
14191460
assert new_strict_mode_config['read_rate_limit'] == 2
14201461
# assert write rate limit is not unset because it is currently not supported
1421-
assert new_strict_mode_config['write_rate_limit'] == 1
1462+
assert new_strict_mode_config['write_rate_limit'] == 1

0 commit comments

Comments
 (0)