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

fix: always fetch database list on bootstrap payload #11934

Merged
merged 1 commit into from
Dec 9, 2020
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
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]:
Copy link
Member Author

Choose a reason for hiding this comment

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

I know this is very similar to find_by_ids but decided to go explicit over dry. We're already pretty meta here so didn't want to add a layer to safe a few lines of code.

"""
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 @@ -2720,17 +2721,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