joaopamaral opened a new pull request, #37574:
URL: https://github.com/apache/superset/pull/37574

   ### SUMMARY
   
   Add `has_app_context()` check before calling `db.session.remove()` in the 
`task_postrun` signal handler to prevent `RuntimeError: Working outside of 
application context` when the handler fires after the Flask app context has 
been torn down.
   
   This issue occurs when running Celery workers with the prefork pool, where 
the `task_postrun` signal can fire after the app context is no longer available.
   
   Fixes #36892
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A - backend fix
   
   ### TESTING INSTRUCTIONS
   
   1. Run Celery worker with prefork pool:
      ```bash
      celery --app=superset.tasks.celery_app:app worker --pool=prefork -O fair 
-c 4
      ```
   2. Trigger alerts/reports jobs
   3. Verify no `RuntimeError: Working outside of application context` appears 
in logs
   
   Alternatively, run the new integration test:
   ```bash
   pytest 
tests/integration_tests/celery_tests.py::test_teardown_without_app_context -v
   ```
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: #36892
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


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