apache/superset · error · CommandInvalidError

Could not find a valid command to import file

Error message

Could not find a valid command to import file

What it means

Raised as CommandInvalidError by the chart import dispatcher when every registered import command (per bundle version) either reported IncorrectVersionError (skipped) or failed validation, so no importer claims the bundle. The uploaded chart export's 'version' field does not match any supported importer, or the bundle is malformed for its declared version.

Source

Thrown at superset/commands/chart/importers/dispatcher.py:67

        # iterate over all commands until we find a version that can
        # handle the contents
        for version in command_versions:
            command = version(self.contents, *self.args, **self.kwargs)
            try:
                command.run()
                return
            except IncorrectVersionError:
                logger.debug("File not handled by command, skipping")
            except (CommandInvalidError, ValidationError):
                # found right version, but file is invalid
                logger.info("Command failed validation")
                raise
            except Exception:
                # validation succeeded but something went wrong
                logger.exception("Error running import command")
                raise

        raise CommandInvalidError("Could not find a valid command to import file")

    def validate(self) -> None:
        pass

View on GitHub (pinned to f4587218dd)

Solutions

  1. Open the ZIP and check metadata.yaml's 'version' field against versions supported by your Superset release.
  2. Re-export the bundle from a Superset version at or older than the target instance, then import.
  3. Use the matching import endpoint (dashboard bundles to /api/v1/dashboard/import/) rather than forcing chart-only import.
  4. Update Superset to a release whose importers cover the bundle version.

Example fix

# before: bundle exported from newer Superset (version 2.0 metadata)
client.post('/api/v1/chart/import/', files={'formData': open('new_bundle.zip','rb')})

# after: re-export from a compatible instance or upgrade target
# (ensure metadata.yaml version matches an importer registered in this build)
Defensive patterns

Strategy: validation

Validate before calling

import yaml, zipfile
with zipfile.ZipFile(bundle) as z:
    meta = yaml.safe_load(z.read('metadata.yaml'))
assert meta['version'] in SUPPORTED_IMPORT_VERSIONS, f"unsupported bundle version {meta['version']}"

Type guard

def is_supported_bundle(meta: dict) -> bool:
    return isinstance(meta.get('version'), str) and meta['version'] in SUPPORTED_IMPORT_VERSIONS

Try / catch

from superset.commands.importers.exceptions import CommandInvalidError
try:
    dispatcher.run(import_bundle)
except CommandInvalidError as ex:
    log_and_report_version_mismatch(ex)

Prevention

When it happens

Trigger: POST /api/v1/chart/import/ with a ZIP whose YAML metadata declares an unsupported version; exporting from a newer Superset and importing into an older one; hand-edited or truncated export bundles.

Common situations: Cross-version migrations (downgrades are unsupported); importing a dashboard bundle into the chart-only import endpoint with mismatched metadata; renaming the metadata.yaml keys.

Related errors


AI-assisted analysis of apache/superset@f4587218dd (2026-08-14). Data as JSON: /api/errors/cea969521c2d1a3d. Report an issue: GitHub.