dosubot[bot] commented on issue #30368: URL: https://github.com/apache/superset/issues/30368#issuecomment-2370342611
<!-- Greeting --> Hey there, @tamarinkeisari! 👋 I'm here to help you with any bugs, questions, or even becoming a contributor. Let's squash those bugs together! <!-- Answer --> I found a similar unsolved discussion regarding CSV alerts resulting in an HTTP 500 error, which might be related to your issue. You can check it out [here](https://github.com/apache/superset/discussions/28594) <sup>[[1]](https://github.com/apache/superset/discussions/28594)</sup>. The issue with CSV and text alerts failing with an HTTP 400 error in Superset versions 3.0.0rc1 and 4.0.2 is likely due to the `_get_csv_data` and `_get_embedded_data` methods returning `None`. This results in an "Unexpected missing csv file" or "Unexpected missing embedded data" error. Here is a relevant code snippet: ```python if ( feature_flag_manager.is_feature_enabled("ALERTS_ATTACH_REPORTS") or self._report_schedule.type == ReportScheduleType.REPORT ): if self._report_schedule.report_format == ReportDataFormat.PNG: screenshot_data = self._get_screenshots() if not screenshot_data: error_text = "Unexpected missing screenshot" elif self._report_schedule.report_format == ReportDataFormat.PDF: pdf_data = self._get_pdf() if not pdf_data: error_text = "Unexpected missing pdf" elif ( self._report_schedule.chart and self._report_schedule.report_format == ReportDataFormat.CSV ): csv_data = self._get_csv_data() if not csv_data: error_text = "Unexpected missing csv file" if error_text: return NotificationContent( name=self._report_schedule.name, text=error_text, header_data=header_data, ) if ( self._report_schedule.chart and self._report_schedule.report_format == ReportDataFormat.TEXT ): embedded_data = self._get_embedded_data() ``` The `error_text` is set when `csv_data` or `embedded_data` is `None`, leading to the failure of the alert <sup>[[2]](https://github.com/apache/superset/blob/master/superset/commands/report/execute.py)</sup>. Additionally, the `get_chart_csv_data` function in `superset/utils/csv.py` is responsible for fetching the CSV data. Here is its implementation: ```python def get_chart_csv_data( chart_url: str, auth_cookies: Optional[dict[str, str]] = None ) -> Optional[bytes]: content = None if auth_cookies: opener = urllib.request.build_opener() cookie_str = ";".join([f"{key}={val}" for key, val in auth_cookies.items()]) opener.addheaders.append(("Cookie", cookie_str)) response = opener.open(chart_url) content = response.read() if response.getcode() != 200: raise URLError(response.getcode()) if content: return content return None ``` This function attempts to fetch the CSV data from the provided `chart_url` using authentication cookies if available. If the response code is not 200, it raises an `HTTPError` <sup>[[3]](https://github.com/apache/superset/blob/master/superset/utils/csv.py)</sup>. To gain more insight into why the HTTP 400 error is occurring, you can leverage the additional logging and error handling introduced in newer versions of Superset. The `handle_api_exception` decorator and the `set_app_error_handlers` function include detailed logging for various exceptions, including `HTTPException`, which would cover HTTP 400 errors <sup>[[4]](https://github.com/apache/superset/blob/master/superset/views/error_handling.py)</sup><sup>[[5]](https://github.com/apache/superset/blob/master/superset/views/core.py)</sup><sup>[[6]](https://github.com/apache/superset/blob/master/superset/charts/data/api.py)</sup>. These enhancements in error handling and logging should provide more detailed insights into the causes of HTTP 400 errors. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
