apache / superset

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

Missing CSV file in email of report / alert #28495

Open dufour-yohann opened 6 months ago

dufour-yohann commented 6 months ago

Bug description

When I receive a report or alert of a "Chart" report with "CSV" format, the CSV file is missing

How to reproduce the bug

  1. Go to a table chart edit page (url example: /explore/?form_data_key=...&slice_id=1234) of a non empty dataset : the table must contain records
  2. Click on "..." (right top corner) then "Manage email report" > "Set up an email report"
  3. Choose the name and the schedule you want, and select "Formatted CSV attached in email" in Message content then save
  4. Wait for the report to be sent (according to schedule settings)
  5. Open the email received : you can see that the email is empty (there is only the subject and a link in the email body) and no file is attached => the csv file is missing

Screenshots/recordings

image

Superset version

4.0.1

Python version

I don't know

Node version

I don't know

Browser

Chrome

Additional context

Superset is deployed on AWS ECS with a custom Dockerfile built from the official image of apache/superset:4.0.1

I have checked the logs and no error / python stacktrace are triggered

FEATURE_FLAGS = {
    'ALERT_REPORTS': True,
    'DRILL_TO_DETAIL': True,
    'ENABLE_TEMPLATE_PROCESSING': True,
    'PLAYWRIGHT_REPORTS_AND_THUMBNAILS': True,
    'EMBEDDED_SUPERSET': True
}

ALERT_REPORTS_NOTIFICATION_DRY_RUN = True
SCREENSHOT_LOCATE_WAIT = 100
SCREENSHOT_LOAD_WAIT = 600

class CeleryConfig:
    broker_url = 'redis://%s:%s/0' % (REDIS_HOST, REDIS_PORT)
    imports = ('superset.sql_lab', "superset.tasks", "superset.tasks.thumbnails", )
    result_backend = 'redis://%s:%s/0' % (REDIS_HOST, REDIS_PORT)
    worker_prefetch_multiplier = 10
    task_acks_late = True
    task_annotations = {
        'sql_lab.get_sql_results': {
            'rate_limit': '100/s',
        },
        'email_reports.send': {
            'rate_limit': '1/s',
            'time_limit': 600,
            'soft_time_limit': 600,
            'ignore_result': True,
        },
    }
    beat_schedule = {
        "reports.scheduler": {
            "task": "reports.scheduler",
            "schedule": crontab(minute="*", hour="*"),
        },
        "reports.prune_log": {
            "task": "reports.prune_log",
            "schedule": crontab(minute=10, hour=0),
        },
    }

CELERY_CONFIG = CeleryConfig

# Email configuration
SMTP_HOST = os.getenv("SMTP_HOST")
SMTP_PORT = os.getenv("SMTP_PORT")
SMTP_STARTTLS = True
SMTP_SSL_SERVER_AUTH = True # If your using an SMTP server with a valid certificate
SMTP_SSL = False
SMTP_USER = os.getenv("SMTP_USER")
SMTP_PASSWORD = os.getenv("SMTP_PASSWORD")
SMTP_MAIL_FROM = "x@yyy.com"
EMAIL_REPORTS_SUBJECT_PREFIX = ""

Checklist

dosubot[bot] commented 6 months ago

It looks like the issue with the missing CSV file in email reports/alerts from Apache Superset might be related to the handling of attachments in the email sending process. Here are a few areas to investigate:

  1. CSV Data Generation: Ensure that the CSV content is being generated correctly. The issue might arise if self._content.csv is empty or not set, which would prevent the attachment from being included in the email.

  2. Email Sending Function: The problem could be in how the send_email_smtp function processes attachments. It's called with files=[] and data=content.data, where data should contain the CSV content. If the function doesn't handle this parameter as expected, the attachment might not be added to the email.

  3. Configuration and Logging: Check your Apache Superset and SMTP server configurations for any settings that might affect email attachments. Additionally, enabling more detailed logging in Apache Superset can provide insights. Adjust the logging level to DEBUG to capture detailed information about the email sending process, which could help identify why the CSV file isn't being attached.

To enable detailed logging, adjust the LOG_LEVEL to DEBUG in the Superset configuration file. This will increase log verbosity, providing more information on the email sending process and attachment handling. Be mindful that debug logging can generate a lot of data, so it's best used temporarily for troubleshooting.

These steps should help you narrow down the cause of the issue and find a resolution. If you discover any new details or errors in the logs, sharing those could provide further clues for troubleshooting.

#### Details **Sources** - [superset/reports/notifications/email.py](https://github.com/apache/superset/blob/master/superset/reports/notifications/email.py) - [tests/integration_tests/email_tests.py](https://github.com/apache/superset/blob/master/tests/integration_tests/email_tests.py) - [superset/utils/logging_configurator.py](https://github.com/apache/superset/blob/master/superset/utils/logging_configurator.py) - [superset/commands/report/execute.py](https://github.com/apache/superset/blob/master/superset/commands/report/execute.py) - [superset/reports/notifications/exceptions.py](https://github.com/apache/superset/blob/master/superset/reports/notifications/exceptions.py) - [superset/commands/sql_lab/export.py](https://github.com/apache/superset/blob/master/superset/commands/sql_lab/export.py)
**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.