[PR #30847] fix: replace direct database query with Repository in Conversation.status_count #32983

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

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

State: open
Merged: No


  • Add get_workflow_runs_by_ids batch query method to APIWorkflowRunRepository interface
  • Implement batch query in both SQLAlchemy and Logstore repositories
  • Update Conversation.status_count to use Repository batch query instead of direct PostgreSQL query
  • Logstore implementation supports dual-read fallback to ensure SLS data is accessible
  • Add UUID format validation to prevent SQL injection

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

part of https://github.com/langgenius/dify/issues/23966#issuecomment-3702449662

Problem

  • In SLS single-write mode, Conversation.status_count queries WorkflowRun directly from PostgreSQL, missing new runs stored in SLS. This causes incorrect status statistics: failed runs are not counted, so the console shows all conversations as "success" (failed count is always 0).
  • This is caused by incomplete storage abstraction: the code bypasses the Repository layer and queries PostgreSQL directly, breaking compatibility with SLS storage.

Solution

  • Added get_workflow_runs_by_ids() batch query method to APIWorkflowRunRepository interface
  • Implemented batch query in both SQLAlchemy and Logstore repositories
  • Updated Conversation.status_count to use Repository batch query instead of direct PostgreSQL query
  • Logstore implementation supports dual-read fallback to ensure SLS data is accessible

Screenshots

Before After
Always show success image display the status correctly 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 make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/30847 **State:** open **Merged:** No --- - Add get_workflow_runs_by_ids batch query method to APIWorkflowRunRepository interface - Implement batch query in both SQLAlchemy and Logstore repositories - Update Conversation.status_count to use Repository batch query instead of direct PostgreSQL query - Logstore implementation supports dual-read fallback to ensure SLS data is accessible - Add UUID format validation to prevent SQL injection > [!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 <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> part of https://github.com/langgenius/dify/issues/23966#issuecomment-3702449662 ### Problem - In SLS single-write mode, Conversation.status_count queries WorkflowRun directly from PostgreSQL, missing new runs stored in SLS. This causes incorrect status statistics: failed runs are not counted, so the console shows all conversations as "success" (failed count is always 0). - This is caused by incomplete storage abstraction: the code bypasses the Repository layer and queries PostgreSQL directly, breaking compatibility with SLS storage. ### Solution - Added get_workflow_runs_by_ids() batch query method to APIWorkflowRunRepository interface - Implemented batch query in both SQLAlchemy and Logstore repositories - Updated Conversation.status_count to use Repository batch query instead of direct PostgreSQL query - Logstore implementation supports dual-read fallback to ensure SLS data is accessible ## Screenshots | Before | After | |--------|-------| | Always show success <img alt="image" src="https://github.com/user-attachments/assets/17b89fe8-e7ac-443f-a882-a0986a6fea52" /> | display the status correctly <img alt="image" src="https://github.com/user-attachments/assets/4e34e3b3-9d5d-47e8-bd06-d3fe9de0343d" />| ## 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 `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:27 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32983