fix: always fetch database list on bootstrap payload (#11934)

There was this weird bug happening only when `SQLLAB_BACKEND_PERSISTENCE
= False` where if no database had been selected, there would be some
issue.

This makes sure that the store is populated consistently with the list
of database connections regardless of `SQLLAB_BACKEND_PERSISTENCE`. It
also uses the DAO to fetch database and will apply the RBAC-related
filters if any, the same way that the API does.
This commit is contained in:
Maxime Beauchemin
2020-12-09 09:36:18 -08:00
committed by GitHub
parent cc44a2c01b
commit 150c8e36b1
2 changed files with 20 additions and 7 deletions

View File

@@ -76,6 +76,19 @@ class BaseDAO:
).apply(query, None)
return query.all()
@classmethod
def find_all(cls) -> List[Model]:
"""
Get all that fit the `base_filter`
"""
query = db.session.query(cls.model_cls)
if cls.base_filter:
data_model = SQLAInterface(cls.model_cls, db.session)
query = cls.base_filter( # pylint: disable=not-callable
"id", data_model
).apply(query, None)
return query.all()
@classmethod
def create(cls, properties: Dict[str, Any], commit: bool = True) -> Model:
"""

View File

@@ -63,6 +63,7 @@ from superset.connectors.sqla.models import (
)
from superset.dashboards.commands.importers.v0 import ImportDashboardsCommand
from superset.dashboards.dao import DashboardDAO
from superset.databases.dao import DatabaseDAO
from superset.databases.filters import DatabaseFilter
from superset.exceptions import (
CertificateException,
@@ -2721,17 +2722,16 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
.first()
)
databases: Dict[int, Any] = {}
databases: Dict[int, Any] = {
database.id: {
k: v for k, v in database.to_json().items() if k in DATABASE_KEYS
}
for database in DatabaseDAO.find_all()
}
queries: Dict[str, Any] = {}
# These are unnecessary if sqllab backend persistence is disabled
if is_feature_enabled("SQLLAB_BACKEND_PERSISTENCE"):
databases = {
database.id: {
k: v for k, v in database.to_json().items() if k in DATABASE_KEYS
}
for database in db.session.query(Database).all()
}
# return all user queries associated with existing SQL editors
user_queries = (
db.session.query(Query)