Don't allow queries with 'IN' predicate with an empty sequence
While SQLalchemy-based storage tests running (test_storage_scenarios.test_query_filter_with_empty_in) there was invoked SAWarning: The IN-predicate on "sample.resource_id" with an empty sequence. Reason is in not checking of 'in' query lists elements number. These queries make no sense, so JSON Schema for this was fixed. Change-Id: I43ea2d20269c9567b3ef99936f63b7c0003170df
This commit is contained in:
parent
ad72ca88ab
commit
52f7c1beaa
|
@ -1167,7 +1167,8 @@ class ValidatedComplexQuery(object):
|
|||
schema_value_in = {
|
||||
"type": "array",
|
||||
"items": {"oneOf": [{"type": "string"},
|
||||
{"type": "number"}]}}
|
||||
{"type": "number"}]},
|
||||
"minItems": 1}
|
||||
|
||||
schema_field = {
|
||||
"type": "object",
|
||||
|
|
|
@ -392,3 +392,9 @@ class TestFilterSyntaxValidation(test.BaseTestCase):
|
|||
self.assertRaises(jsonschema.ValidationError,
|
||||
self.query._validate_filter,
|
||||
filter)
|
||||
|
||||
def test_empty_in_query_not_passing(self):
|
||||
filter = {"in": {"resource_id": []}}
|
||||
self.assertRaises(jsonschema.ValidationError,
|
||||
self.query._validate_filter,
|
||||
filter)
|
||||
|
|
|
@ -943,11 +943,6 @@ class ComplexSampleQueryTest(DBTestBase,
|
|||
self.assertTrue(sample.counter_volume > 0.4)
|
||||
self.assertTrue(sample.counter_volume <= 0.8)
|
||||
|
||||
def test_query_filter_with_empty_in(self):
|
||||
results = list(
|
||||
self.conn.query_samples(filter_expr={"in": {"resource_id": []}}))
|
||||
self.assertEqual(len(results), 0)
|
||||
|
||||
def test_query_simple_metadata_filter(self):
|
||||
self._create_samples()
|
||||
|
||||
|
|
Loading…
Reference in New Issue