Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Set isolation level to READ COMMITTED for testing et al. #28628

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@john-bodley Reading this it looks like everything will be SERIALIZABLE right? we're overriding it in the tests but are we overriding it as READ COMMITTED anywhere else for the other databases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sadpandajoe followed the rabbit hole here, and I think you're right, this will bump all envs who don't set their SQLALCHEMY_ENGINE_OPTIONS to a higher isolation level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this draft? #30174

}

# 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.
Expand Down
7 changes: 6 additions & 1 deletion tests/integration_tests/superset_test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safer than doing a string match.

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
Expand Down
7 changes: 6 additions & 1 deletion tests/integration_tests/superset_test_config_thumbnails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Loading