Open ilsaloving opened 4 days ago
Hey @ilsaloving, I'm here to help you with any bugs, questions, or contributions you have regarding Superset. Let's tackle this together!
To obtain the YAML schema definition for data sources in Superset 4.0.2 using the CLI, you should use the export_datasource_schema
command. Here is the command you need to run:
superset export_datasource_schema
This command will export the datasource YAML schema to stdout. If you want to include parent back references, you can add the -b
flag:
superset export_datasource_schema -b
Regarding the AttributeError
you encountered with the legacy-export-datasource-schema
command, it seems to be related to a change in the export_schema_to_dict
function in dict_import_export.py
. The function was modified to call Database.export_schema
with the parameters recursive=True
and include_parent_ref=back_references
. This change might cause an AttributeError
if the Database
class does not have an export_schema
method.
Here is the relevant code snippet:
def export_schema_to_dict(back_references: bool) -> dict[str, Any]:
"""Exports the supported import/export schema to a dictionary"""
databases = [
Database.export_schema(recursive=True, include_parent_ref=back_references)
]
data = {}
if databases:
data[DATABASES_KEY] = databases
return data
If Database
does not have an export_schema
method, attempting to call it will result in an AttributeError
[1][2].
For the SqlMetric
class, the class_
attribute is not defined. The SqlMetric
class includes attributes such as id
, metric_name
, verbose_name
, metric_type
, description
, d3format
, currency
, warning_text
, table_id
, expression
, and extra
. It also includes relationships, methods, and properties to handle various functionalities related to SQL metrics [3][4].
To resolve the issue, you may need to ensure that the Database
class has the export_schema
method implemented or adjust the code to handle the absence of this method.
To continue talking to Dosu, mention @dosu.
It looks like export_datasource_schema
has been renamed to legacy_export_datasource_schema
- I'm not sure if it's on the path to deprecation or if there's another reason for the rename. @betodealmeida might know.
You may also want to take a look at the Preset CLI (not maintained by the Superset project, but it is built to be compatible with Superset). https://preset.io/blog/version-control-superset-charts-dashboards-superset/
We probably need to update our docs to fix the export_datasource_schema
reference, but I'd like to know more before making a change myself. PRs welcome, of course :D
Bug description
I am trying to figure out how to get data sources created in superset in an automated way. There does not appear to be a CLI command for adding a data source, but it does support importing definitions from yaml files.
According to this doc page, it should be possible to do
superset export_datasource_schema
to get a comprehensive list of yaml directives.As of 4.0.2, this command does not exist:
Additionally, if I try to do
superset legacy-export-datasource-schema
, I get the following error:How to reproduce the bug
Screenshots/recordings
No response
Superset version
4.0.2
Python version
Not applicable
Node version
Not applicable
Browser
Not applicable
Additional context
2024-09-23 19:09:09,339:INFO:root:Configured event logger of type <class 'superset.utils.log.DBEventLogger'> /usr/local/lib/python3.10/site-packages/flask_limiter/extension.py:293: UserWarning: Using the in-memory storage for tracking rate limits as no storage was explicitly specified. This is not recommended for production use. See: https://flask-limiter.readthedocs.io#configuring-a-storage-backend for documentation about configuring the storage backend. warnings.warn( Traceback (most recent call last): File "/usr/local/bin/superset", line 33, in
sys.exit(load_entry_point('apache-superset', 'console_scripts', 'superset')())
File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1130, in call
return self.main(args, kwargs)
File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, ctx.params)
File "/usr/local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(args, kwargs)
File "/usr/local/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, *kwargs)
File "/usr/local/lib/python3.10/site-packages/flask/cli.py", line 357, in decorator
return __ctx.invoke(f, args, kwargs)
File "/usr/local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return callback(*args, **kwargs)
File "/app/superset/cli/importexport.py", line 404, in legacy_export_datasource_schema
data = dict_import_export.export_schema_to_dict(back_references=back_references)
File "/app/superset/utils/dict_import_export.py", line 31, in export_schema_to_dict
Database.export_schema(recursive=True, include_parent_ref=back_references)
File "/app/superset/models/helpers.py", line 240, in export_schema
child_class.export_schema(
File "/app/superset/models/helpers.py", line 238, in export_schema
child_class = cls.mapper.relationships[column].argument.class
AttributeError: type object 'SqlMetric' has no attribute 'class'. Did you mean: 'class__'?
Checklist