dosubot[bot] commented on issue #37075:
URL: https://github.com/apache/superset/issues/37075#issuecomment-3742645935

   <!-- Answer -->
   You're hitting two separate issues in Superset v6:
   
   1. **"Working outside of application context" error:**  
   This happens because the Celery teardown handler in 
`superset/tasks/celery_app.py` calls `db.session.remove()` without checking for 
a Flask app context. This is a known issue in v6. To fix it, wrap the call in 
an app context or check for one before removing the session. For example:
   ```python
   from flask import has_app_context
   if has_app_context():
       db.session.remove()
   ```
   or
   ```python
   with flask_app.app_context():
       db.session.remove()
   ```
   This prevents the teardown from running outside the Flask context and avoids 
the runtime error.  
   [See discussion and code 
reference](https://github.com/apache/superset/issues/36892)
   
   2. **CSV report HTTP 400 error:**  
   There are a few possible causes:
   - If your chart uses server pagination, Superset may generate a ZIP file 
with multiple CSVs but send it as a `.csv` attachment. Try renaming the 
attachment to `.zip` and see if it opens. Fixing this requires updating the 
code that sets the attachment filename to use `.zip` when appropriate.  
   [See related issue and 
workaround](https://github.com/apache/superset/issues/32886)
   - If you use custom CSV delimiters (like `;`), the email report workflow may 
ignore your `CSV_EXPORT` config and fail to parse the CSV, resulting in a 
400/500 error. The fix is to update `superset/charts/client_processing.py` to 
use your delimiter and decimal settings when parsing CSV for email reports.  
   [See explanation and code 
fix](https://github.com/apache/superset/issues/36682)
   
   **Other things to check:**  
   - Make sure the `ALERT_REPORTS` feature flag is enabled and your email 
(SMTP) and Celery configs are correct.
   - Test your SMTP config with a simple Python script to rule out connectivity 
issues.
   - If you recently upgraded, note that recipient logic changed: for reports 
from charts/dashboards, the current user's email is always used as the 
recipient. If your user profile lacks an email, report creation will fail.  
   [See merged PR for details](https://github.com/apache/superset/pull/36981)
   
   Let me know if you need code snippets for any of these fixes or want to dig 
deeper into a specific error!
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/28a53ca0-ea4c-4db3-b12d-dfc5589cb305?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/28a53ca0-ea4c-4db3-b12d-dfc5589cb305?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/28a53ca0-ea4c-4db3-b12d-dfc5589cb305?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/28a53ca0-ea4c-4db3-b12d-dfc5589cb305?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/28a53ca0-ea4c-4db3-b12d-dfc5589cb305?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/28a53ca0-ea4c-4db3-b12d-dfc5589cb305?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/28a53ca0-ea4c-4db3-b12d-dfc5589cb305?feedback_type=other)</sup>
   
   [![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=You%27re%20hitting%20two%20separate%20issues%20in%20Superset%20v6%3A%0A%0A1.%20%2A%2A%22Working%20outside%20of%20application%20context%22%20error%3A%2A%2A%20%20%0AThis%20happens%20because%20the%20Celery%20teardown%20handler%20in%20%60superset/tasks/celery_app.py%60%20calls%20%60db.session.remove%28%29%60%20without%20checking%20for%20a%20Flask%20app%20context.%20This%20is%20a%20known%20issue%20in%20v6.%20To%20fix%20it%2C%20wrap%20the%20call%20in%20an%20app%20context%20or%20check%20for%20one%20before%20removing%20the%20session.%20For%20example%3A%0A%60%60%60python%0Afrom%20flask%20import%20has_app_context%0Aif%20has_app_context%28%29%3A%0A%20%20%20%20db.session.remove%28%29%0A%60%60%60%0Aor%0A%60%60%60python%0Awith%20flask_app.app_context%28%29%3A%0A
 
%20%20%20%20db.session.remove%28%29%0A%60%60%60%0AThis%20prevents%20the%20teardown%20from%20running%20outside%20the%20Flask%20context%20and%20avoids%20the%20runtime%20error.%20%20%0A%5BSee%20discussion%20and%20code%20reference%5D%28https%3A//github.com/apache/superset/issues/36892%29%0A%0A2.%20%2A%2ACSV%20report%20HTTP%20400%20error%3A%2A%2A%20%20%0AThere%20are%20a%20few%20possible%20causes%3A%0A-%20If%20your%20chart%20uses%20server%20pagination%2C%20Superset%20may%20generate%20a%20ZIP%20file%20with%20multiple%20CSVs%20but%20send%20it%20as%20a%20%60.csv%60%20attachment.%20Try%20renaming%20the%20attachment%20to%20%60.zip%60%20and%20see%20if%20it%20opens.%20Fixing%20this%20requires%20updating%20the%20code%20that%20sets%20the%20attachment%20filename%20to%20use%20%60.zip%60%20when%20appropriate.%20%20%0A%5BSee%20related%20issue%20and%20workaround%5D%28https%3A//github.com/apache/superset/issues/32886%29%0A-%20If%20you%20use%20custom%20CSV%20delimiters%20%28like%20%60%3B%60%29%2C%20the%2
 
0email%20report%20workflow%20may%20ignore%20your%20%60CSV_EXPORT%60%20config%20and%20fail%20to%20parse%20the%20CSV%2C%20resulting%20in%20a%20400/500%20error.%20The%20fix%20is%20to%20update%20%60superset/charts/client_processing.py%60%20to%20use%20your%20delimiter%20and%20decimal%20settings%20when%20parsing%20CSV%20for%20email%20reports.%20%20%0A%5BSee%20explanation%20and%20code%20fix%5D%28https%3A//github.com/apache/superset/issues/36682%29%0A%0A%2A%2AOther%20things%20to%20check%3A%2A%2A%20%20%0A-%20Make%20sure%20the%20%60ALERT_REPORTS%60%20feature%20flag%20is%20enabled%20and%20your%20email%20%28SMTP%29%20and%20Celery%20configs%20are%20correct.%0A-%20Test%20your%20SMTP%20config%20with%20a%20simple%20Python%20script%20to%20rule%20out%20connectivity%20issues.%0A-%20If%20you%20recently%20upgraded%2C%20note%20that%20recipient%20logic%20changed%3A%20for%20reports%20from%20charts/dashboards%2C%20the%20current%20user%27s%20email%20is%20always%20used%20as%20the%20recipient.%20If%20your%20us
 
er%20profile%20lacks%20an%20email%2C%20report%20creation%20will%20fail.%20%20%0A%5BSee%20merged%20PR%20for%20details%5D%28https%3A//github.com/apache/superset/pull/36981%29%0A%0ALet%20me%20know%20if%20you%20need%20code%20snippets%20for%20any%20of%20these%20fixes%20or%20want%20to%20dig%20deeper%20into%20a%20specific%20error%21)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/37075)


-- 
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]

Reply via email to