ForgotPasswordResetApi session management #10226

Closed
opened 2026-02-21 18:44:17 -05:00 by yindo · 0 comments
Owner

Originally created by @jushiwei1995 on GitHub (Mar 10, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

``https://github.com/langgenius/dify/blob/9b2a9260efb9bd906784aa55917bfe9885f7cddf/api/controllers/console/auth/forgot_password.py#L122

begin with line 122

The main issue is the mixing of database sessions. In your code, you create a session using:

    account = session.execute(
        select(Account).filter_by(email=reset_data.get("email"))
    ).scalar_one_or_none()

However, when updating the account object, you call db.session.commit() instead of using the same session that you opened. This can lead to several problems:

Detached Object Issue: Once the with block finishes, the session is closed and the account object becomes detached. Using a different session to commit changes might not work as expected.
Transaction Inconsistency: Using different sessions for querying and updating may result in inconsistent behavior or failure to persist changes.

Suggested Fix:
Keep the operations within the same session.

✔️ Expected Behavior

Keep the operations within the same session.

Actual Behavior

No response

Originally created by @jushiwei1995 on GitHub (Mar 10, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.0.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ``https://github.com/langgenius/dify/blob/9b2a9260efb9bd906784aa55917bfe9885f7cddf/api/controllers/console/auth/forgot_password.py#L122 begin with line 122 The main issue is the mixing of database sessions. In your code, you create a session using: ```with Session(db.engine) as session: account = session.execute( select(Account).filter_by(email=reset_data.get("email")) ).scalar_one_or_none() ``` However, when updating the account object, you call db.session.commit() instead of using the same session that you opened. This can lead to several problems: Detached Object Issue: Once the with block finishes, the session is closed and the account object becomes detached. Using a different session to commit changes might not work as expected. Transaction Inconsistency: Using different sessions for querying and updating may result in inconsistent behavior or failure to persist changes. Suggested Fix: Keep the operations within the same session. ### ✔️ Expected Behavior Keep the operations within the same session. ### ❌ Actual Behavior _No response_
yindo closed this issue 2026-02-21 18:44:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#10226