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: chart import error with virtual dataset #19782

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions superset/charts/commands/importers/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def _import(
config.update(
{
"datasource_id": dataset.id,
"datasource_type": "view"
if dataset.is_sqllab_view
else "table",
"datasource_type": "table",
Copy link
Member

Choose a reason for hiding this comment

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

I am not familiar with this part, but the datasource_type = view seems the correct value here. Here is the schema defination for updating chart.

@betodealmeida could you take a look?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but virtual dataset should have view as a datasource_type?

Copy link
Member

Choose a reason for hiding this comment

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

I'm also not familiar with this part, so I created a chart from a virtual dataset and it has datasource_type set to table. Looking at the source code it seems that "view" here means a database VIEW, not a virtual dataset, and is only used by the DB engine spec to retrieve the list of views from a given database:

elif datasource_type == "view":
all_datasources += database.get_all_view_names_in_schema(
schema=schema,
force=True,
cache=database.table_cache_enabled,
cache_timeout=database.table_cache_timeout,
)

So I think this should be table, and we also need to fix this line:

"datasource_type": "view" if dataset.is_sqllab_view else "table",

"datasource_name": dataset.table_name,
}
)
Expand Down
2 changes: 1 addition & 1 deletion superset/commands/importers/v1/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _import( # pylint: disable=arguments-differ, too-many-locals, too-many-bran

dataset_info[str(dataset.uuid)] = {
"datasource_id": dataset.id,
"datasource_type": "view" if dataset.is_sqllab_view else "table",
"datasource_type": "table",
"datasource_name": dataset.table_name,
}

Expand Down