Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
fix(datasource): use case-insensitive check for LIMIT
Browse files Browse the repository at this point in the history
Before applying our own `LIMIT 1`, we check if the query already has a
`LIMIT` clause by a simple substring search. This had two issues:
- It did not work when `LIMIT` was in uppercase
- It could match "limit" in a column or table name

Changed this to use a case-insensitive regex search which also looks for
whitespace around `LIMIT`. Since "limit" as a column or table name will
need to enclosed in double quotes, this regex will not match them.
  • Loading branch information
Samyak2 committed Sep 7, 2022
1 parent 8a9c727 commit 95e90c8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chaos_genius/connectors/base_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import exc as sqlalchemy_exc
Expand Down Expand Up @@ -104,7 +105,7 @@ def get_schema_metadata_from_query(self, query):
query = query.strip()
if query[-1] == ";":
query = query[:-1]
if "limit" not in query:
if not re.search(r"\s+limit\s+", query, re.IGNORECASE):
query += " limit 1 "

query_text = text(query)
Expand Down

0 comments on commit 95e90c8

Please sign in to comment.