From 0c60b73b15c6a2e1b89f784cb2faf2fc44a9e866 Mon Sep 17 00:00:00 2001 From: ylamgarchal Date: Wed, 18 Dec 2024 14:12:41 +0100 Subject: [PATCH] query_es_dsl: force query to be fully parsed or fail. nrt added Change-Id: Ibe9c3252780eff3281df3829c6a2509b421cca09 --- dci/analytics/query_es_dsl.py | 2 +- dci/api/v1/analytics.py | 2 +- tests/analytics/test_query_es_dsl.py | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dci/analytics/query_es_dsl.py b/dci/analytics/query_es_dsl.py index 5ae16092c..6c3e3a3a7 100644 --- a/dci/analytics/query_es_dsl.py +++ b/dci/analytics/query_es_dsl.py @@ -81,7 +81,7 @@ def parse(q): - return query.parseString(q).asList() + return query.parseString(q, parseAll=True).asList() _op_to_es_op = {"<": "lt", "<=": "lte", ">": "gt", ">=": "gte"} diff --git a/dci/api/v1/analytics.py b/dci/api/v1/analytics.py index 976fc7537..3689ca2e3 100644 --- a/dci/api/v1/analytics.py +++ b/dci/api/v1/analytics.py @@ -321,7 +321,7 @@ def tasks_jobs(user): es_query = build_es_query(args) except Exception as e: logger.error(f"error while building the elastic query: {e}") - raise dci_exc.DCIException("error while building the elastic query") + raise dci_exc.DCIException("syntax error while parsing the query") try: res = requests.get( diff --git a/tests/analytics/test_query_es_dsl.py b/tests/analytics/test_query_es_dsl.py index 42aa81ecb..e23df55fb 100644 --- a/tests/analytics/test_query_es_dsl.py +++ b/tests/analytics/test_query_es_dsl.py @@ -24,6 +24,9 @@ def test_parse_query_invalid(): with pytest.raises(pp.ParseException): qed.parse("toto") + with pytest.raises(pp.ParseException): + qed.parse("(toto=titi) and (lol=mdr") + def test_parse_query_valid(): ret = qed.parse("f1=v1")