[PR #30521] fix: [Bug] knowledge_retrieval_node fails when using Rerank Model: "Working outside of application context" #30511 #32857

Closed
opened 2026-02-21 20:52:12 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/30521

State: closed
Merged: No


…orking outside of application context" #30511

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fix: #30511 [Bug] knowledge_retrieval_node fails when using Rerank Model: "Working outside of application context"

In the call chain, db.engine requires a Flask application context, but reranking_enable logic is currently executed outside of the application context.

with flask_app.app_context():
    ...
# ← the application context has already been exited here

if reranking_enable:
    data_post_processor = DataPostProcessor(...)

As a result, when the reranking logic initializes and eventually accesses db.engine, Flask raises “Working outside of application context.”

Screenshots

1f651ca1-ebe8-46b4-a508-8fe5d60a9fd6

Before

bd0d0caa5a82a4cd652024f20b0a29da

After

ok

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/30521 **State:** closed **Merged:** No --- …orking outside of application context" #30511 > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary fix: #30511 [Bug] knowledge_retrieval_node fails when using Rerank Model: "Working outside of application context" In the call chain, `db.engine` requires a Flask **application context**, but `reranking_enable` logic is currently executed **outside** of the application context. ``` with flask_app.app_context(): ... # ← the application context has already been exited here if reranking_enable: data_post_processor = DataPostProcessor(...) ``` As a result, when the reranking logic initializes and eventually accesses `db.engine`, Flask raises **“Working outside of application context.”** ## Screenshots <img width="593" height="465" alt="1f651ca1-ebe8-46b4-a508-8fe5d60a9fd6" src="https://github.com/user-attachments/assets/10be36f0-36b4-49c1-816c-67d3ef5bf581" /> ### Before <img width="627" height="983" alt="bd0d0caa5a82a4cd652024f20b0a29da" src="https://github.com/user-attachments/assets/c3245bb6-dfea-49ad-86fc-ed590dfbd9e0" /> ### After <img width="596" height="790" alt="ok" src="https://github.com/user-attachments/assets/4d8ef0c9-c807-4d51-a42f-9976b491c9d7" /> ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:12 -05:00
yindo closed this issue 2026-02-21 20:52:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32857