Skip to content

refactor: migrate session.query to select API in document indexing sync task#34813

Merged
asukaminato0721 merged 1 commit intolanggenius:mainfrom
RenzoMXD:refactor/sqlalchemy-select-document-indexing-sync-task
Apr 9, 2026
Merged

refactor: migrate session.query to select API in document indexing sync task#34813
asukaminato0721 merged 1 commit intolanggenius:mainfrom
RenzoMXD:refactor/sqlalchemy-select-document-indexing-sync-task

Conversation

@RenzoMXD
Copy link
Copy Markdown
Contributor

@RenzoMXD RenzoMXD commented Apr 9, 2026

Summary

  • Migrate session.query() to SQLAlchemy 2.0 select() API in tasks/document_indexing_sync_task.py
  • .query(Model).where(...).first() / .filter_by(...).first()session.scalar(select(Model).where(...).limit(1))
  • Minimal test mock updates: .query.return_value.where.return_value.first.side_effectsession.scalar.side_effect

Test plan

  • All 4 unit tests pass
  • basedpyright: 0 errors, 0 warnings
  • mypy: 0 errors

Part of #22668

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Pyrefly Diff

No changes detected.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 9, 2026
@asukaminato0721 asukaminato0721 requested a review from Copilot April 9, 2026 05:44
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Notion document indexing sync Celery task to use SQLAlchemy 2.0 select()-style ORM reads, improving typing and modernizing query usage in line with issue #22668.

Changes:

  • Replaced multiple session.query(...).where/filter_by(...).first() lookups with session.scalar(select(...).where(...).limit(1)) in document_indexing_sync_task.
  • Updated unit test DB session mocks to reflect the new session.scalar() call pattern.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
api/tasks/document_indexing_sync_task.py Migrates ORM reads from legacy Query API to SQLAlchemy 2.0 select() + session.scalar() while preserving existing control flow.
api/tests/unit_tests/tasks/test_document_indexing_sync_task.py Adjusts session mocks from chained .query().where().first() to session.scalar.side_effect to match the refactor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Merged via the queue into langgenius:main with commit f5ea61e Apr 9, 2026
30 of 31 checks passed
@RenzoMXD RenzoMXD deleted the refactor/sqlalchemy-select-document-indexing-sync-task branch April 9, 2026 11:50
HanqingZ pushed a commit to HanqingZ/dify that referenced this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants