Skip to content

Commit

Permalink
query_es_dsl: force query to be fully parsed
Browse files Browse the repository at this point in the history
or fail.

nrt added

Change-Id: Ibe9c3252780eff3281df3829c6a2509b421cca09
  • Loading branch information
ylamgarchal committed Dec 18, 2024
1 parent ad13182 commit 0c60b73
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dci/analytics/query_es_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion dci/api/v1/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions tests/analytics/test_query_es_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0c60b73

Please sign in to comment.