diff --git a/superset/config.py b/superset/config.py index fa4ad4a29f765..ea3ac079cf2a4 100644 --- a/superset/config.py +++ b/superset/config.py @@ -196,6 +196,13 @@ def _try_json_readsha(filepath: str, length: int) -> str | None: # SQLALCHEMY_DATABASE_URI = 'mysql://myapp@localhost/myapp' # SQLALCHEMY_DATABASE_URI = 'postgresql://root:password@localhost/myapp' +# The default MySQL isolation level is REPEATABLE READ whereas the default PostgreSQL +# isolation level is READ COMMITTED. All backends should use READ COMMITTED (or similar) +# to help ensure consistent behavior. +SQLALCHEMY_ENGINE_OPTIONS = { + "isolation_level": "SERIALIZABLE", # SQLite does not support READ COMMITTED. +} + # In order to hook up a custom password store for all SQLALCHEMY connections # implement a function that takes a single argument of type 'sqla.engine.url', # returns a password and set SQLALCHEMY_CUSTOM_PASSWORD_STORE. diff --git a/tests/integration_tests/superset_test_config.py b/tests/integration_tests/superset_test_config.py index 5ef3e2aa0a9c2..e0a1123950d50 100644 --- a/tests/integration_tests/superset_test_config.py +++ b/tests/integration_tests/superset_test_config.py @@ -20,6 +20,8 @@ from copy import copy from datetime import timedelta +from sqlalchemy.engine import make_url + from superset.config import * # noqa: F403 from superset.config import DATA_DIR from tests.integration_tests.superset_test_custom_template_processors import ( @@ -52,12 +54,15 @@ if "UPLOAD_FOLDER" in os.environ: # noqa: F405 UPLOAD_FOLDER = os.environ["UPLOAD_FOLDER"] # noqa: F405 -if "sqlite" in SQLALCHEMY_DATABASE_URI: +if make_url(SQLALCHEMY_DATABASE_URI).get_backend_name() == "sqlite": logger.warning( # noqa: F405 "SQLite Database support for metadata databases will be " "removed in a future version of Superset." ) +if make_url(SQLALCHEMY_DATABASE_URI).get_backend_name() in ("postgresql", "mysql"): + SQLALCHEMY_ENGINE_OPTIONS["isolation_level"] = "READ COMMITTED" # noqa: F405 + # Speeding up the tests.integration_tests. PRESTO_POLL_INTERVAL = 0.1 HIVE_POLL_INTERVAL = 0.1 diff --git a/tests/integration_tests/superset_test_config_thumbnails.py b/tests/integration_tests/superset_test_config_thumbnails.py index a7c0368ff4477..8fda61e804a3f 100644 --- a/tests/integration_tests/superset_test_config_thumbnails.py +++ b/tests/integration_tests/superset_test_config_thumbnails.py @@ -17,6 +17,8 @@ # type: ignore from copy import copy +from sqlalchemy.engine import make_url + from superset.config import * # noqa: F403 from superset.config import DATA_DIR @@ -33,12 +35,15 @@ if "SUPERSET__SQLALCHEMY_DATABASE_URI" in os.environ: # noqa: F405 SQLALCHEMY_DATABASE_URI = os.environ["SUPERSET__SQLALCHEMY_DATABASE_URI"] # noqa: F405 -if "sqlite" in SQLALCHEMY_DATABASE_URI: +if make_url(SQLALCHEMY_DATABASE_URI).get_backend_name() == "sqlite": logger.warning( # noqa: F405 "SQLite Database support for metadata databases will be removed \ in a future version of Superset." ) +if make_url(SQLALCHEMY_DATABASE_URI).get_backend_name() in ("postgresql", "mysql"): + SQLALCHEMY_ENGINE_OPTIONS["isolation_level"] = "READ COMMITTED" # noqa: F405 + SQL_SELECT_AS_CTA = True SQL_MAX_ROW = 666