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

feat(reports): xlsx attachments #19810

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

cemremengu
Copy link
Contributor

@cemremengu cemremengu commented Apr 21, 2022

SUMMARY

Most people and departments in enterprise companies are addicted to spreadsheets. Currently our customers are heavily demanding Excel reports and, unfortunately, we have failed to persuade them to continue with CSV.

So here I am with a PR that adds the ability to attach XLSX files as report data and notifications (slack). If this one gets approved, I will also attempt to implement PDF in a similar way.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

image

image

TESTING INSTRUCTIONS

Try sending an xlsx report or notification. I wasn't able to test slack since I don't use it actively but implemented it nevertheless for completeness.

Known Problems

Currently the first column is displayed like

image

It can be monkey patched but it should be fixed naturally once/if #19735 lands.

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

@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #19810 (77b9047) into master (62b4564) will decrease coverage by 0.05%.
The diff coverage is 76.36%.

❗ Current head 77b9047 differs from pull request most recent head 3edb8d5. Consider uploading reports for the commit 3edb8d5 to get more accurate results

@@            Coverage Diff             @@
##           master   #19810      +/-   ##
==========================================
- Coverage   68.98%   68.93%   -0.05%     
==========================================
  Files        1903     1904       +1     
  Lines       74126    74101      -25     
  Branches     8110     8120      +10     
==========================================
- Hits        51138    51085      -53     
- Misses      20876    20904      +28     
  Partials     2112     2112              
Flag Coverage Δ
hive 53.85% <30.76%> (-0.16%) ⬇️
javascript 55.65% <86.20%> (+0.02%) ⬆️
mysql ?
postgres 79.32% <65.38%> (-0.07%) ⬇️
presto 53.78% <30.76%> (-0.16%) ⬇️
python 83.25% <65.38%> (-0.11%) ⬇️
sqlite 77.82% <65.38%> (-0.07%) ⬇️
unit 54.54% <30.76%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...acy-preset-chart-deckgl/src/components/Tooltip.tsx 0.00% <0.00%> (ø)
...lugins/plugin-chart-table/src/utils/formatValue.ts 66.66% <0.00%> (-3.93%) ⬇️
...c/components/Chart/DrillDetail/DrillDetailPane.tsx 75.32% <ø> (ø)
...rset-frontend/src/components/ReportModal/index.tsx 79.03% <ø> (ø)
...-frontend/src/components/TableCollection/index.tsx 100.00% <ø> (ø)
...mponents/DataTablesPane/components/SamplesPane.tsx 97.67% <ø> (ø)
...ataTablesPane/components/SingleQueryResultPane.tsx 85.71% <ø> (ø)
...-frontend/src/features/alerts/AlertReportModal.tsx 54.44% <ø> (ø)
superset/datasets/api.py 87.95% <ø> (ø)
superset/security/manager.py 93.83% <ø> (ø)
... and 13 more

... and 7 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@cemremengu cemremengu force-pushed the email_xlsx branch 2 times, most recently from 2b556b2 to 5c04c2a Compare April 26, 2022 07:30
@smartsense-as
Copy link

Any update on this?

@etadelta222
Copy link

@cemremengu , I've posted this in superset slack (https://apache-superset.slack.com/archives/CCKHMGRRB/p1662748936923259) and there's some feedback. Hopefully get some 👀 on it. Thank you for creating this PR!

@cemremengu
Copy link
Contributor Author

You are welcome! I am happy to continue once maintainers have time to chime in.

Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Just a few small suggestions.

tests/integration_tests/reports/commands_tests.py Outdated Show resolved Hide resolved
superset/reports/commands/execute.py Outdated Show resolved Hide resolved
@cemremengu
Copy link
Contributor Author

@EugeneTorap thanks for the heads up! Just pushed the updates, my testing environment is limited now so apologies for any inconvenience

@sfirke sfirke mentioned this pull request Nov 7, 2022
@artemonsh
Copy link
Contributor

@cemremengu you forgot to add
image

to the file superset/reports/commands/execute.py

Otherwise, email reports look like this:
image

@EugeneTorap
Copy link
Contributor

@cemremengu Thanks. Can you format a file with black to fix CI: Python Misc / pre-commit (3.8)?

pip install black
black superset/tests/integration_tests/reports/commands_tests.py

@EugeneTorap
Copy link
Contributor

@cemremengu We use Excel name instead of XLSX in our #22006 PR
Can we use the Excel name for email alert/report UI logic?

image

@cemremengu
Copy link
Contributor Author

cemremengu commented Dec 6, 2022

@EugeneTorap you mean replacing all occurrences of XLSX with Excel like EXPORT_TO_EXCEL right ?

@EugeneTorap
Copy link
Contributor

EugeneTorap commented Dec 6, 2022

I think yes, need to replace all UI label from XLSX to Excel in this PR for name consistency.
@villebro @zhaoyongjie @michael-s-molina What do you think?

@cemremengu
Copy link
Contributor Author

Just to clarify @EugeneTorap should something like this be

<StyledRadio value="EXCEL">{t('Send as Excel')}</StyledRadio>

or

<StyledRadio value="Excel">{t('Send as Excel')}</StyledRadio>

@EugeneTorap
Copy link
Contributor

EugeneTorap commented Dec 6, 2022

@cemremengu Value must be XLSX but label is Excel

<StyledRadio value="XLSX">{t('Send as Excel')}</StyledRadio>

@cemremengu
Copy link
Contributor Author

@EugeneTorap Fixed 2 of them, I agree it is better like this.

@rusackas
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@rusackas Ephemeral environment spinning up at http://35.86.251.160:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@EugeneTorap
Copy link
Contributor

@geido @dpgaspar Can you review it? Maybe you have a good suggestion to improve the code?

@dpgaspar dpgaspar self-requested a review January 31, 2023 10:27
@kakoni
Copy link
Contributor

kakoni commented Feb 6, 2023

@cemremengu Btw, python integration tests are currently failing for this,
superset.reports.commands.exceptions.ReportScheduleUnexpectedError: argument of type 'method' is not iterable

This is because there is line self._report_schedule.report_format in ReportDataFormat.table_like: it should be self._report_schedule.report_format in ReportDataFormat.table_like():

@cemremengu
Copy link
Contributor Author

@kakoni thank you for the tip!

@mdeshmu
Copy link
Contributor

mdeshmu commented May 18, 2023

@cemremengu did you get time to fix this ?

@cemremengu
Copy link
Contributor Author

Not sure what I need to fix. As far as I remember failing tests were flaky (I cannot see the CI log anymore)

@EugeneTorap @rusackas how should we proceed with this PR?

@rusackas
Copy link
Member

Easiest way to get CI logs again is to close/reopen it, or apply new commits (like fixing the merge conflicts would do)

@cemremengu
Copy link
Contributor Author

cemremengu commented Jun 14, 2023

@rusackas rebased, not sure what the failing tests are about.

@kakoni had doubts about _get_data vs _get_csv_data in previous discussions. Once we settle that I think we can merge?

@rusackas
Copy link
Member

The test-mysql, test-postgres, and test-sqlite actions are failing due to this:

FAILED tests/integration_tests/reports/commands_tests.py::test_email_chart_report_schedule_with_csv - superset.reports.commands.exceptions.ReportScheduleDataFrameFailedError: Failed generating dataframe Input string must be text, not bytes

the pre-commit check is failing because of a linting error. You can probably just run pre-commit run --all-files and commit any changes to clear that up.

@cemremengu cemremengu force-pushed the email_xlsx branch 2 times, most recently from f7678b1 to ab7fb9c Compare June 15, 2023 09:20
@cemremengu
Copy link
Contributor Author

@rusackas thanks for pointing these out! Cypress tests are failing but those seem to be caused by something else?

I decided to revert back to the old _get_csv_data way to benefit from the post processing. The only problem now seems that the excel contains the index column even though I export it with Index=False. Should just force drop the first column? Any ideas about that?

image

@mdeshmu
Copy link
Contributor

mdeshmu commented Oct 5, 2023

@rusackas can we please unblock this by answering @cemremengu's question in last comment.

@rusackas
Copy link
Member

Hi all! Sorry for not answering the last question, but this came up in my "PRs that haven't been touched in forever" audit, and I didn't realize I was the one blocking things. I actually don't know the answer to the standing question, but if anyone/everyone wants to spin this up, let's at least start with a rebase. I'll convert this to Draft mode in the meantime, and ping @yousoph and @eschutho who may have interest in helping usher this along. Let's see if we can get it across the finish line!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants