Documentssuperset
Chart Configuration Serialization
Chart Configuration Serialization
Type
Topic
Status
Published
Created
Jul 27, 2026
Updated
Jul 27, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

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 the form_data property, which deserializes the JSON and merges in live fields like datasource, slice_id, and viz_type.
  • query_context — a serialized QueryContext blob used by the query pipeline .

The set of fields included in export/import is defined by two class-level lists on Slice :

ListFields
export_fieldsslice_name, description, certified_by, certification_details, datasource_type, datasource_name, viz_type, params, query_context, cache_timeout
extra_import_fieldsis_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():

  1. export_to_dict() extracts export_fields with recursive=False, include_defaults=True, export_uuids=True.
  2. Key removalREMOVE_KEYS = ["datasource_type", "datasource_name", "url_params"] are stripped . datasource_type/datasource_name are redundant once dataset_uuid is present; url_params are environment-local.
  3. params JSON expansion — the params string is decoded from JSON into a Python dict before YAML serialization, producing human-readable YAML rather than an escaped string .
  4. Extra fields appended: version ("1.0.0"), dataset_uuid (the linked SqlaTable.uuid), and tags when the TAGGING_SYSTEM feature 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 :

LocationFieldFormat
Top-level configdatasource_id, datasource_type, datasource_namescalar values
config["params"]datasource"{id}__{type}" string
config["query_context"]datasource, form_data.datasource, each query.datasourceobject {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:

  1. Looks up the chart by uuid; checks write permissions and ownership before overwriting .
  2. Calls filter_chart_annotations() — mutates params to keep only FORMULA-type annotation layers; EVENT and other types that depend on external objects are dropped.
  3. Re-serializes params from dict back to JSON string .
  4. Calls migrate_chart() to upgrade legacy viz types via the processors registry, which also rewrites query_context.form_data to match the migrated params.
  5. 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#

FilePurpose
superset/models/slice.pySlice model — params/query_context columns, form_data property, export_fields
superset/commands/chart/export.pyExportChartsCommand — serialization, key removal, params JSON expansion
superset/commands/chart/importers/v1/__init__.pyImportChartsCommand — orchestration, UUID→ID resolution
superset/commands/chart/importers/v1/utils.pyimport_chart(), filter_chart_annotations(), migrate_chart()
superset/commands/utils.pyupdate_chart_config_dataset() — datasource reference rewriting
superset/models/helpers.pyImportExportMixin.export_to_dict() / import_from_dict() — field-gated serialization base