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

feat: Surface parameters fields for database model #14646

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 11 additions & 0 deletions superset-frontend/src/views/CRUD/data/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ type DatabaseUser = {
last_name: string;
};

// type DatabaseParameters = {
// database: string;
// engine: string;
// host: string;
// password?: string;
// port: number;
// query: Object;
// username: string;
// };

export type DatabaseObject = {
// Connection + general
id?: number;
Expand All @@ -30,6 +40,7 @@ export type DatabaseObject = {
created_by?: null | DatabaseUser;
changed_on_delta_humanized?: string;
changed_on?: string;
// parameters?: DatabaseParameters;

// Performance
cache_timeout?: string;
Expand Down
1 change: 1 addition & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"allow_ctas",
"allow_cvas",
"allow_dml",
"parameters",
"force_ctas_schema",
"allow_multi_schema_metadata_fetch",
"impersonate_user",
Expand Down
18 changes: 15 additions & 3 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from sqlalchemy.sql import expression, Select

from superset import app, db_engine_specs, is_feature_enabled
from superset.db_engine_specs.base import TimeGrain
from superset.db_engine_specs.base import BasicParametersMixin, TimeGrain
from superset.extensions import cache_manager, encrypted_field_factory, security_manager
from superset.models.helpers import AuditMixinNullable, ImportExportMixin
from superset.models.tags import FavStarUpdater
Expand Down Expand Up @@ -212,6 +212,7 @@ def data(self) -> Dict[str, Any]:
"allows_cost_estimate": self.allows_cost_estimate,
"allows_virtual_table_explore": self.allows_virtual_table_explore,
"explore_database_id": self.explore_database_id,
"parameters": self.parameters,
}

@property
Expand All @@ -222,6 +223,17 @@ def unique_name(self) -> str:
def url_object(self) -> URL:
return make_url(self.sqlalchemy_uri_decrypted)

@property
def parameters(self) -> Optional[Dict[str, Any]]:
# Build parameters if db_engine_spec is a subclass of BasicParametersMixin
parameters = {"engine": self.backend}
Copy link
Member

Choose a reason for hiding this comment

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

so for sqlalchemy forms, we're only going to return engine? Maybe that should be the only required type then, it looks like.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea good catch i'll make sure to update the type on the types file


if issubclass(self.db_engine_spec, BasicParametersMixin):
Copy link
Member

Choose a reason for hiding this comment

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

After we add BQ we need to change this, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea that PR will have the updated logic here to allow us to pass Big Query credentials

uri = make_url(self.sqlalchemy_uri_decrypted)
return {**parameters, **self.db_engine_spec.get_parameters_from_uri(uri)}

return parameters

@property
def backend(self) -> str:
sqlalchemy_url = make_url(self.sqlalchemy_uri_decrypted)
Expand Down Expand Up @@ -568,10 +580,10 @@ def get_all_schema_names(

@property
def db_engine_spec(self) -> Type[db_engine_specs.BaseEngineSpec]:
return self.get_db_engine_spec_for_backend(self.backend)
engines = db_engine_specs.get_engine_specs()
return engines.get(self.backend, db_engine_specs.BaseEngineSpec)

@classmethod
@utils.memoized
def get_db_engine_spec_for_backend(
cls, backend: str
) -> Type[db_engine_specs.BaseEngineSpec]:
Expand Down