apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
62.8k stars 13.87k forks source link

[Bug] [v3.0.4] Dataset serialization can produce bad export. ("An error occurred while importing dataset") #27437

Open maudrid opened 8 months ago

maudrid commented 8 months ago

Bug description

When exporting certain datasets, the serialized version of the dataset is invalid. This causes validation with marshmallow to fail when you try to import it again.

How to reproduce the bug

In the superset UI:

  1. Open any dataset
  2. Go to the settings tab and enter any value in the TEMPLATE PARAMETERS field and save. This is enough to trigger the bug, but you can also remove the value from the TEMPLATE PARAMETERS field and save again, and the bug will still persist.
  3. Export the dataset using the export feature.
  4. Immediately try to import the same dataset again.

Screenshots/recordings

image

image

Superset version

3.0.4

Python version

3.9

Node version

16

Browser

Chrome

Additional context

In order to work around this issue:

  1. Open the zip file and extract the dataset yaml file
  2. Find the field called template_params. If the dataset is broken the value of this field will be a string value or an empty string like this: template_params: ''
  3. Change the value to null like this -> template_params: null
  4. Save the file and place it back into the zip file that was exported.
  5. Import the dataset back into superset

Stack:

2024-03-08 11:59:32,978:WARNING:superset.views.base:CommandException
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/usr/local/lib/python3.9/site-packages/flask_appbuilder/security/decorators.py", line 95, in wraps
    return f(self, *args, **kwargs)
  File "/app/superset/views/base_api.py", line 127, in wraps
    raise ex
  File "/app/superset/views/base_api.py", line 121, in wraps
    duration, response = time_function(f, self, *args, **kwargs)
  File "/app/superset/utils/core.py", line 1535, in time_function
    response = func(*args, **kwargs)
  File "/app/superset/utils/log.py", line 255, in wrapper
    value = f(*args, **kwargs)
  File "/app/superset/views/base_api.py", line 108, in wraps
    return f(self, *args, **kwargs)
  File "/app/superset/datasets/api.py", line 937, in import_
    command.run()
  File "/app/superset/datasets/commands/importers/dispatcher.py", line 64, in run
    raise exc
  File "/app/superset/datasets/commands/importers/dispatcher.py", line 57, in run
    command.run()
  File "/app/superset/commands/importers/v1/__init__.py", line 73, in run
    self.validate()
  File "/app/superset/commands/importers/v1/__init__.py", line 111, in validate
    raise CommandInvalidError(
superset.commands.exceptions.CommandInvalidError: Error importing dataset

Checklist

fmannhardt commented 8 months ago

It also occurs in 3.1.1 for me. Easy to reproduce by simply changing template_params: null to template_params: '' in any of the datasets exported.