You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2024/09/06 01:32:16 UTC
(superset) branch fix_mysql_isolation created (now 1a3cb6216e)
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a change to branch fix_mysql_isolation
in repository https://gitbox.apache.org/repos/asf/superset.git
at 1a3cb6216e fix: set default mysql isolation level to 'READ COMMITTED'
This branch includes the following new commits:
new 1a3cb6216e fix: set default mysql isolation level to 'READ COMMITTED'
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: fix: set default mysql isolation level to 'READ COMMITTED'
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch fix_mysql_isolation
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 1a3cb6216e092bb22c2904e7aa338cdef766ccb9
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Thu Sep 5 18:27:03 2024 -0700
fix: set default mysql isolation level to 'READ COMMITTED'
https://github.com/apache/superset/pull/28628 had the virtuous intent to align mysql and postgres to a consistent isolation_level (READ COMMITTED), which seems fitted for Superset. Though instead of doing this, and because sqlite doesn't support that specific one, it set the default to SERIALIZABLE which seems to exist by many engines.
Here I'm realizing we need dynamic defaults for isolation_level based on which engine is in used, which can't be done in config.py as we don't know yet what engine will be set by the admin at that time. So I thought the superset/initialization package might be the right place for this.
Open to other solutions, but I think this one works.
* using DB_CONNECTION_MUTATOR, but that one applies only to analytics workloads, not the metadata db
---
.gitattributes | 1 +
superset/config.py | 7 -------
superset/initialization/__init__.py | 12 ++++++++++++
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/.gitattributes b/.gitattributes
index 79f44a6b26..5f47e6acc8 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
docker/**/*.sh text eol=lf
+*.svg binary
diff --git a/superset/config.py b/superset/config.py
index 670c518931..4e6e84af4c 100644
--- a/superset/config.py
+++ b/superset/config.py
@@ -196,13 +196,6 @@ SQLALCHEMY_DATABASE_URI = (
# 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/superset/initialization/__init__.py b/superset/initialization/__init__.py
index 2601cda9d7..4ed4d82eb1 100644
--- a/superset/initialization/__init__.py
+++ b/superset/initialization/__init__.py
@@ -482,12 +482,24 @@ class SupersetAppInitializer: # pylint: disable=too-many-public-methods
self.configure_wtf()
self.configure_middlewares()
self.configure_cache()
+ self.set_db_default_isolation()
with self.superset_app.app_context():
self.init_app_in_ctx()
self.post_init()
+ def set_db_default_isolation(self) -> None:
+ # This block sets the default isolation level for mysql to READ COMMITTED if not
+ # specified in the config. You can set your isolation in the config by using
+ # SQLALCHEMY_ENGINE_OPTIONS
+ eng_options = self.config["SQLALCHEMY_ENGINE_OPTIONS"] or {}
+ isolation_level = eng_options.get("isolation_level")
+ if not isolation_level and self.config["SQLALCHEMY_DATABASE_URI"].startswith(
+ "mysql"
+ ):
+ db.engine.execution_options(isolation_level="READ COMMITTED")
+
def configure_auth_provider(self) -> None:
machine_auth_provider_factory.init_app(self.superset_app)