Skip to content

Commit

Permalink
fix: always fetch database list on bootstrap payload (#11934)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mistercrunch authored Dec 9, 2020
1 parent cc44a2c commit 150c8e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 13 additions & 0 deletions superset/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ def find_by_ids(cls, model_ids: List[int]) -> List[Model]:
).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:
"""
Expand Down
14 changes: 7 additions & 7 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
)
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,
Expand Down Expand Up @@ -2721,17 +2722,16 @@ def _get_sqllab_tabs(user_id: int) -> Dict[str, Any]:
.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)
Expand Down

0 comments on commit 150c8e3

Please sign in to comment.