apache / superset

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

Exporting issue #29394

Open chengkaijie0 opened 3 months ago

chengkaijie0 commented 3 months ago

Bug description

I am currently facing an issue in exporting my dashboards from page 3 onwards. Is there a way to go about solving this issue?

How to reproduce the bug

.

Screenshots/recordings

Capture

Superset version

master / latest-dev

Python version

I don't know

Node version

I don't know

Browser

Chrome

Additional context

No response

Checklist

dosubot[bot] commented 3 months ago

Hi @chengkaijie0! 👋 I'm a bot here to help you with bugs, questions, and becoming a contributor. Let's tackle this issue together!

To resolve the issue of being unable to export your dashboards from page 3 onwards in a multi-page PDF document, you should investigate the _get_screenshots and _get_pdf methods in the BaseReportState class. These methods are responsible for generating the screenshots and compiling them into a PDF.

Here is the relevant code snippet:

def _get_screenshots(self) -> list[bytes]:
    """
    Get chart or dashboard screenshots
    :raises: ReportScheduleScreenshotFailedError
    """
    url = self._get_url()
    _, username = get_executor(
        executor_types=app.config["ALERT_REPORTS_EXECUTE_AS"],
        model=self._report_schedule,
    )
    user = security_manager.find_user(username)
    if self._report_schedule.chart:
        window_width, window_height = app.config["WEBDRIVER_WINDOW"]["slice"]
        window_size = (
            self._report_schedule.custom_width or window_width,
            self._report_schedule.custom_height or window_height,
        )
        screenshot: Union[ChartScreenshot, DashboardScreenshot] = ChartScreenshot(
            url,
            self._report_schedule.chart.digest,
            window_size=window_size,
            thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"],
        )
    else:
        window_width, window_height = app.config["WEBDRIVER_WINDOW"]["dashboard"]
        window_size = (
            self._report_schedule.custom_width or window_width,
            self._report_schedule.custom_height or window_height,
        )
        screenshot = DashboardScreenshot(
            url,
            self._report_schedule.dashboard.digest,
            window_size=window_size,
            thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
        )
    try:
        image = screenshot.get_screenshot(user=user)
    except SoftTimeLimitExceeded as ex:
        logger.warning("A timeout occurred while taking a screenshot.")
        raise ReportScheduleScreenshotTimeout() from ex
    except Exception as ex:
        raise ReportScheduleScreenshotFailedError(
            f"Failed taking a screenshot {str(ex)}"
        ) from ex
    if not image:
        raise ReportScheduleScreenshotFailedError()
    return [image]

def _get_pdf(self) -> bytes:
    """
    Get chart or dashboard pdf
    :raises: ReportSchedulePdfFailedError
    """
    screenshots = self._get_screenshots()
    pdf = build_pdf_from_screenshots(screenshots)

    return pdf

The _get_screenshots method captures screenshots of the charts or dashboards, and the _get_pdf method compiles these screenshots into a PDF. If the issue is occurring from page 3 onwards, it might be due to a timeout or an error in capturing the screenshots.

To debug this issue, you can:

  1. Check for Timeouts: Ensure that the screenshot capturing process is not timing out. The SoftTimeLimitExceeded exception indicates a timeout.
  2. Error Handling: Look for any exceptions being raised in the _get_screenshots method. The ReportScheduleScreenshotFailedError exception indicates a failure in taking a screenshot.
  3. Logging: Add additional logging to capture more details about the failure. This can help identify if the issue is with specific pages or charts.
  4. Configuration: Verify the configuration settings for WEBDRIVER_WINDOW to ensure that the window size is appropriate for capturing the entire dashboard.

By addressing these points, you should be able to identify and resolve the issue with exporting your dashboards in a multi-page PDF document [1].

To continue talking to Dosu, mention @dosu.

rusackas commented 3 months ago

Possibly related to (or even a duplicate of?) https://github.com/apache/superset/issues/29324