dify/api/core/rag
GitHub Contributor 3b8559521d fix: use isolated session in _on_query to prevent premature commit
The _on_query method was calling db.session.commit() on the Flask-scoped
SQLAlchemy session, which committed all pending dirty state from the
current request — not just the DatasetQuery audit rows.

This broke transaction isolation: if the downstream workflow failed, the
subsequent db.session.rollback() could not revert the already-committed
modifications (e.g. token deductions, partial node executions), leaving
dirty data in the database.

The same file already demonstrates the correct pattern in
_on_retrieval_end, which uses sessionmaker(bind=db.engine).begin() with an
independent session. This change applies the same approach to _on_query.

Additionally fixed a latent bug where dataset_queries.add_all() was called
inside the loop on every iteration, re-adding previously accumulated rows.

Fixes #37886
2026-06-26 04:09:16 +08:00
..
cleaner refactor(api): type bare dict/list annotations in remaining rag folder (#33775) 2026-03-20 03:31:06 +09:00
data_post_processor chore: reorg imports (#35308) 2026-04-16 08:50:02 +00:00
datasource feat: trace document retrieval (#37283) 2026-06-11 02:39:59 +00:00
docstore chore: DocumentSegment to Typebase (#35635) 2026-05-12 07:02:17 +00:00
embedding ci: add flag for linter (#37018) 2026-06-08 04:53:12 +00:00
entities docs: enrich generated service API descriptions (#37615) 2026-06-18 08:43:39 +00:00
extractor fix(watercrawl): don't disable request timeouts with timeout=None (#37685) 2026-06-22 03:08:58 +00:00
index_processor chore: make AccountService.load_user use passed session (#37764) 2026-06-24 07:29:12 +00:00
models chore: reorg imports (#35308) 2026-04-16 08:50:02 +00:00
pipeline chore: use from __future__ import annotations (#30254) 2026-01-06 23:57:20 +09:00
rerank ci: add flag for linter (#37018) 2026-06-08 04:53:12 +00:00
retrieval fix: use isolated session in _on_query to prevent premature commit 2026-06-26 04:09:16 +08:00
splitter ci: add flag for linter (#37018) 2026-06-08 04:53:12 +00:00
summary_index refactor(api): migrate core RAG layer to SQLAlchemy 2.0 select() API (#34965) 2026-04-11 16:32:20 +00:00
__init__.py Feat/dify rag (#2528) 2024-02-22 23:31:57 +08:00