Chart Configuration Serialization#
Chart configuration in Superset is stored in the Slice model (slices table) across two MediumText columns:
params— the full chart form configuration as a JSON string . Exposed at runtime as theform_dataproperty, which deserializes the JSON and merges in live fields likedatasource,slice_id, andviz_type.query_context— a serializedQueryContextblob used by the query pipeline .
The set of fields included in export/import is defined by two class-level lists on Slice :
| List | Fields |
|---|---|
export_fields | slice_name, description, certified_by, certification_details, datasource_type, datasource_name, viz_type, params, query_context, cache_timeout |
extra_import_fields | is_managed_externally, external_url (accepted on import only, not exported) |
ImportExportMixin.import_from_dict() gates field acceptance to export_fields + extra_import_fields, preventing injection of arbitrary columns.
Export: ExportChartsCommand#
ExportChartsCommand extends ExportModelsCommand and produces a ZIP containing metadata.yaml, per-chart YAML files under charts/, and optionally related dataset and tag YAMLs.
The core serialization happens in _file_content():
export_to_dict()extractsexport_fieldswithrecursive=False, include_defaults=True, export_uuids=True.- Key removal —
REMOVE_KEYS = ["datasource_type", "datasource_name", "url_params"]are stripped .datasource_type/datasource_nameare redundant oncedataset_uuidis present;url_paramsare environment-local. paramsJSON expansion — theparamsstring is decoded from JSON into a Python dict before YAML serialization, producing human-readable YAML rather than an escaped string .- Extra fields appended:
version("1.0.0"),dataset_uuid(the linkedSqlaTable.uuid), andtagswhen theTAGGING_SYSTEMfeature flag is enabled .
Related datasets are exported transitively via ExportDatasetsCommand.
Import: ImportChartsCommand Pipeline#
ImportChartsCommand._import() orchestrates a multi-step pipeline that resolves UUID-based references to local database IDs before writing any rows:
1. Collect dataset_uuids from chart configs
2. Collect database_uuids from dataset configs
3. import_database() for each referenced database
4. import_dataset() with resolved database_id
5. update_chart_config_dataset() — rewrite datasource refs
6. import_chart() — write the Slice row
7. import_tag() if TAGGING_SYSTEM enabled
Datasource Reference Rewriting#
Before import_chart() is called, update_chart_config_dataset() rewrites all datasource references using the newly imported dataset's local ID. It patches three levels simultaneously :
| Location | Field | Format |
|---|---|---|
| Top-level config | datasource_id, datasource_type, datasource_name | scalar values |
config["params"] | datasource | "{id}__{type}" string |
config["query_context"] | datasource, form_data.datasource, each query.datasource | object {id, type} / string |
If query_context JSON cannot be parsed, it is set to None .
import_chart() Steps#
import_chart() in superset/commands/chart/importers/v1/utils.py:
- Looks up the chart by
uuid; checks write permissions and ownership before overwriting . - Calls
filter_chart_annotations()— mutatesparamsto keep onlyFORMULA-type annotation layers;EVENTand other types that depend on external objects are dropped. - Re-serializes
paramsfrom dict back to JSON string . - Calls
migrate_chart()to upgrade legacy viz types via theprocessorsregistry, which also rewritesquery_context.form_datato match the migrated params. - Calls
Slice.import_from_dict()to upsert the row .
filter_box charts are silently skipped by the outer import loop before import_chart() is reached .
Key Source Files#
| File | Purpose |
|---|---|
superset/models/slice.py | Slice model — params/query_context columns, form_data property, export_fields |
superset/commands/chart/export.py | ExportChartsCommand — serialization, key removal, params JSON expansion |
superset/commands/chart/importers/v1/__init__.py | ImportChartsCommand — orchestration, UUID→ID resolution |
superset/commands/chart/importers/v1/utils.py | import_chart(), filter_chart_annotations(), migrate_chart() |
superset/commands/utils.py | update_chart_config_dataset() — datasource reference rewriting |
superset/models/helpers.py | ImportExportMixin.export_to_dict() / import_from_dict() — field-gated serialization base |