fix: preventing sql lab None limit value (#17155)

* fix: preventing sql lab None limit value

* test: create a test for the fix

* pylint (#17172)

* add test (#17173)

Co-authored-by: Hugh A. Miles II <hughmil3s@gmail.com>
This commit is contained in:
Amit Miran
2021-10-20 23:43:14 +03:00
committed by GitHub
parent aa0f4d6c4f
commit 029ed90afb
2 changed files with 38 additions and 6 deletions

View File

@@ -44,6 +44,7 @@ from superset.sql_lab import (
execute_sql_statement,
get_sql_results,
SqlLabException,
apply_limit_if_exists,
)
from superset.sql_parse import CtasMethod
from superset.utils.core import (
@@ -990,6 +991,29 @@ class TestSqlLab(SupersetTestCase):
]
}
def test_apply_limit_if_exists_when_incremented_limit_is_none(self):
sql = """
SET @value = 42;
SELECT @value AS foo;
"""
database = get_example_database()
mock_query = mock.MagicMock()
mock_query.limit = 300
final_sql = apply_limit_if_exists(database, None, mock_query, sql)
assert final_sql == sql
def test_apply_limit_if_exists_when_increased_limit(self):
sql = """
SET @value = 42;
SELECT @value AS foo;
"""
database = get_example_database()
mock_query = mock.MagicMock()
mock_query.limit = 300
final_sql = apply_limit_if_exists(database, 1000, mock_query, sql)
assert "LIMIT 1000" in final_sql
@pytest.mark.parametrize("spec", [HiveEngineSpec, PrestoEngineSpec])
def test_cancel_query_implicit(spec: BaseEngineSpec) -> None: