Skip to content

Commit 9390319

Browse files
committed
add basic openapi test
1 parent 247c58e commit 9390319

2 files changed

Lines changed: 41 additions & 1 deletion

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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,46 @@ 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+
"unindexed_filtering_retrieve": False,
1357+
})
1358+
1359+
# Now it should fail
1360+
query_fail = query_request()
1361+
assert not query_fail.ok
1362+
assert "discount_price" in query_fail.json()['status']['error']
1363+
assert "formula expression" in query_fail.json()['status']['error']
1364+
1365+
13261366
def test_strict_mode_read_rate_limiting_small_replenish(collection_name):
13271367
"""
13281368
If our read rate limit capacity is larger, test that when exhausting it

0 commit comments

Comments
 (0)