mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore: Support SET & SHOW commands as read only SQL commands (#11868)
* Support SET & SHOW commands as read only SQL commands * Move is_readonly definition into the engine spec * Rename & use super() Co-authored-by: bogdan kyryliuk <bogdankyryliuk@dropbox.com>
This commit is contained in:
@@ -14,19 +14,20 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from tests.test_app import app # isort:skip
|
||||
|
||||
import datetime
|
||||
from unittest import mock
|
||||
|
||||
from superset.db_engine_specs import engines
|
||||
from superset.db_engine_specs.base import BaseEngineSpec, builtin_time_grains
|
||||
from superset.db_engine_specs.sqlite import SqliteEngineSpec
|
||||
from superset.sql_parse import ParsedQuery
|
||||
from superset.utils.core import get_example_database
|
||||
from tests.db_engine_specs.base_tests import TestDbEngineSpec
|
||||
|
||||
from ..fixtures.pyodbcRow import Row
|
||||
|
||||
from tests.test_app import app # isort:skip
|
||||
|
||||
|
||||
class TestDbEngineSpecs(TestDbEngineSpec):
|
||||
def test_extract_limit_from_query(self, engine_spec_class=BaseEngineSpec):
|
||||
@@ -239,3 +240,15 @@ class TestDbEngineSpecs(TestDbEngineSpec):
|
||||
]
|
||||
result = BaseEngineSpec.pyodbc_rows_to_tuples(data)
|
||||
self.assertListEqual(result, data)
|
||||
|
||||
|
||||
def test_is_readonly():
|
||||
def is_readonly(sql: str) -> bool:
|
||||
return BaseEngineSpec.is_readonly_query(ParsedQuery(sql))
|
||||
|
||||
assert not is_readonly("SHOW LOCKS test EXTENDED")
|
||||
assert not is_readonly("SET hivevar:desc='Legislators'")
|
||||
assert not is_readonly("UPDATE t1 SET col1 = NULL")
|
||||
assert is_readonly("EXPLAIN SELECT 1")
|
||||
assert is_readonly("SELECT 1")
|
||||
assert is_readonly("WITH (SELECT 1) bla SELECT * from bla")
|
||||
|
||||
Reference in New Issue
Block a user