Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't export dashboards with CLI if 'admin' user is not created #28689

Open
3 tasks
xavier-GitHub76 opened this issue May 24, 2024 · 1 comment
Open
3 tasks
Assignees
Labels
change:backend Requires changing the backend dashboard:export Related to exporting dashboards

Comments

@xavier-GitHub76
Copy link
Contributor

Bug description

Hello,
with Superset 3.1.1, I can't export dashboards with CLI if 'admin' user is not created

There should be a -u option to specify the admin account to use

Actually, on all branchs, 'admin' is hard coded :
https://github.com/apache/superset/blob/master/superset/cli/importexport.py
image

Best regards

How to reproduce the bug

I have an admin user 'xavier’ (user 'admin' is not created)
image

If I export / import from web app with user ‘xavier’, it's OK

with CLI, I have an error "AttributeError: 'NoneType' object has no attribute 'is_anonymous'"
image

To succed, user 'admin' must exist
image
image

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
@dosubot dosubot bot added change:backend Requires changing the backend dashboard:export Related to exporting dashboards labels May 24, 2024
Copy link

dosubot bot commented May 24, 2024

To address the issue of exporting dashboards using the CLI in Superset 3.1.1 when the 'admin' user is not created, you can modify the export_dashboards function to include a -u option. This allows you to specify a different admin account. Here is the updated function:

@click.command()
@with_appcontext
@click.option(
    "--dashboard-file",
    "-f",
    help="Specify the file to export to",
)
@click.option(
    "--username",
    "-u",
    required=True,
    help="Specify the user name to use for exporting dashboards",
)
def export_dashboards(dashboard_file: Optional[str] = None, username: Optional[str] = None) -> None:
    """Export dashboards to ZIP file"""
    from superset.commands.dashboard.export import ExportDashboardsCommand
    from superset.models.dashboard import Dashboard

    g.user = security_manager.find_user(username=username)

    dashboard_ids = [id_ for (id_,) in db.session.query(Dashboard.id).all()]
    timestamp = datetime.now().strftime("%Y%m%dT%H%M%S")
    root = f"dashboard_export_{timestamp}"
    dashboard_file = dashboard_file or f"{root}.zip"

    try:
        with ZipFile(dashboard_file, "w") as bundle:
            for file_name, file_content in ExportDashboardsCommand(dashboard_ids).run():
                with bundle.open(f"{root}/{file_name}", "w") as fp:
                    fp.write(file_content().encode())
    except Exception:
        logger.exception(
            "There was an error when exporting the dashboards, please check "
            "the exception traceback in the log"
        )
        sys.exit(1)

This modification allows you to specify a different admin account using the -u option when exporting dashboards [1].

Additionally, there are existing command-line options in the Superset CLI that allow specifying a user for other commands, such as importing dashboards and datasources. These options are implemented using the --username or -u flag [1].

However, the current tests for the export_dashboards function do not cover scenarios where the 'admin' user does not exist. All tests assume the existence of the 'admin' user [2][3].

Details

About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:backend Requires changing the backend dashboard:export Related to exporting dashboards
Projects
None yet
Development

No branches or pull requests

2 participants