refactor(Dashboard): Fetch dashboard screenshot via dedicated endpoint
SUMMARY
A dashboard can have an image attached in the markdown component that is hosted on a server that does not have proper CORS settings. Due to limitations of html2canvas, both PDF and image download will fail.
For reference from html2canvas:
All the images that the script uses need to reside under the same origin for it to be able to read them without the assistance of a proxy. Similarly, if you have other canvas elements on the page, which have been tainted with cross-origin content, they will become dirty and no longer readable by html2canvas.
This PR introduces the necessary frontend changes to defer the generation of the screenshot to a newly built endpoint. See https://github.com/apache/superset/pull/29187
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
- Select a Dashboard and a specific tab
- Download the dashboard as an image or PDF via the dedicated menu items
- Wait for the download to complete
- The screenshot should be of the chosen type and depict the target tab
ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in SIP-59)
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
/testenv up
@kgabryje Ephemeral environment spinning up at http://54.186.201.2:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.
I couldn't get it to work on ephemeral env (both image and pdf)
EDIT: Sorry, I didn't notice that the endpoint PR is not merged yet.
/testenv up
@geido Ephemeral environment spinning up at http://52.36.201.158:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.
/testenv up
@geido Ephemeral environment spinning up at http://35.95.67.178:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.
Ephemeral environment shutdown and build artifacts deleted.
Hi there.
Hitting #29719 too, I’ve updated to 4.1.0rc2. When exporting as PDF, I now get
(dis)appearing several times, but I never get the PDF output.
Python 3.11.7 venv on Rocky Linux 9.4 x86_64, backend is PostgreSQL 16.4 through pgbouncer 1.23.1 (coming from PGDG repo) using pool_mode=session.
I do lack logs, the only thing I have is:
Sep 09 07:53:28 superset gunicorn[2297879]: df = self.database.get_df(
Sep 09 07:53:28 superset gunicorn[2297879]: ^^^^^^^^^^^^^^^^^^^^^
Sep 09 07:53:28 superset gunicorn[2297879]: File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/superset/models/core.py", line 677, in get_df
Sep 09 07:53:28 superset gunicorn[2297879]: self.db_engine_spec.execute(cursor, sql_, self)
Sep 09 07:53:28 superset gunicorn[2297879]: File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/superset/db_engine_specs/base.py", line 1835, in execute
Sep 09 07:53:28 superset gunicorn[2297879]: raise cls.get_dbapi_mapped_exception(ex) from ex
Sep 09 07:53:28 superset gunicorn[2297879]: File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/superset/db_engine_specs/base.py", line 1831, in execute
Sep 09 07:53:28 superset gunicorn[2297879]: cursor.execute(query)
Sep 09 07:53:28 superset gunicorn[2297879]: psycopg2.errors.DivisionByZero: division by zero
Sep 09 07:55:44 superset gunicorn[2297879]: 2024-09-09 07:55:44,224:INFO:superset.dashboards.api:Triggering screenshot ASYNC
Trying to dig deeper and have proper logs. If anyone has a clue, I can give it a try. Thanks ! EDIT: div by zero error is very likely due to a SQL query ran from the dashboard, so it’s not the good path. Have found nothing about export or pdf in logs, still digging (btw had to roll back to 4.0.2 as cross-filtering looked broken and it’s heavily used so I won’t be able to debug 4.1.0rc2 pdf export much further)
Sep 09 06:18:35 superset gunicorn[2297879]: 2024-09-09 06:18:35,167:ERROR:superset.utils.json:JSON is not valid Expecting value: line 1 column 1 (char 0)
Sep 09 06:18:35 superset gunicorn[2297879]: Traceback (most recent call last):
Sep 09 06:18:35 superset gunicorn[2297879]: File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/superset/utils/json.py", line 244, in loads
Sep 09 06:18:35 superset gunicorn[2297879]: return simplejson.loads(
Sep 09 06:18:35 superset gunicorn[2297879]: ^^^^^^^^^^^^^^^^^
Sep 09 06:18:35 superset gunicorn[2297879]: File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/simplejson/__init__.py", line 514, in loads
Sep 09 06:18:35 superset gunicorn[2297879]: return _default_decoder.decode(s)
Sep 09 06:18:35 superset gunicorn[2297879]: ^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 09 06:18:35 superset gunicorn[2297879]: File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/simplejson/decoder.py", line 386, in decode
Sep 09 06:18:35 superset gunicorn[2297879]: obj, end = self.raw_decode(s)
Sep 09 06:18:35 superset gunicorn[2297879]: ^^^^^^^^^^^^^^^^^^
Sep 09 06:18:35 superset gunicorn[2297879]: File "/home/ZZZ/superset_3.11/lib64/python3.11/site-packages/simplejson/decoder.py", line 416, in raw_decode
Sep 09 06:18:35 superset gunicorn[2297879]: return self.scan_once(s, idx=_w(s, idx).end())
Sep 09 06:18:35 superset gunicorn[2297879]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This may be the culprit of PDF export failure but can’t be sure about that.
Hope that helps anyway. Thanks