Code Monkey home page Code Monkey logo

Comments (1)

dosubot avatar dosubot commented on July 4, 2024 3

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.

from superset.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.