[PR #23996] fix: move database service call inside session context in workflow draft variable API #30467

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

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

State: closed
Merged: Yes


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

This PR fixes a database session lifecycle management issue in the workflow draft variable API. The WorkflowDraftVariableService.list_variables_without_values() method was being called outside of the database session context manager, which could lead to accessing a closed database session and potential connection management issues.

Changes made:

  • Moved the draft_var_srv.list_variables_without_values() call inside the with Session() context manager block
  • This ensures the database session remains active during the service method execution
  • Improves resource management and prevents potential database connection leaks

Technical details:
The issue was in controllers/console/app/workflow_draft_variable.py in the WorkflowDraftVariableCollectionApi.get() method, where the service call was executed after the session context had already been closed.

Screenshots

Before After
image ...

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/23996 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 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 This PR fixes a database session lifecycle management issue in the workflow draft variable API. The `WorkflowDraftVariableService.list_variables_without_values()` method was being called outside of the database session context manager, which could lead to accessing a closed database session and potential connection management issues. **Changes made:** - Moved the `draft_var_srv.list_variables_without_values()` call inside the `with Session()` context manager block - This ensures the database session remains active during the service method execution - Improves resource management and prevents potential database connection leaks **Technical details:** The issue was in `controllers/console/app/workflow_draft_variable.py` in the `WorkflowDraftVariableCollectionApi.get()` method, where the service call was executed after the session context had already been closed. ## Screenshots | Before | After | |--------|-------| | <img width="2804" height="412" alt="image" src="https://github.com/user-attachments/assets/ccf72f15-c7b0-4ba3-ae8b-297a2d18a4cb" /> | ... | ## 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:47:33 -05:00
yindo closed this issue 2026-02-21 20:47:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30467