Skip to content

test: migrate document indexing task tests to SQLAlchemy 2.0 select API#35145

Merged
asukaminato0721 merged 2 commits intolanggenius:mainfrom
bohdansolovie:chore/sqlalchemy2-document-indexing-update-tests
Apr 14, 2026
Merged

test: migrate document indexing task tests to SQLAlchemy 2.0 select API#35145
asukaminato0721 merged 2 commits intolanggenius:mainfrom
bohdansolovie:chore/sqlalchemy2-document-indexing-update-tests

Conversation

@bohdansolovie
Copy link
Copy Markdown
Contributor

@bohdansolovie bohdansolovie commented Apr 14, 2026

Summary

  • Migrate remaining legacy ORM query usage in two document indexing integration test modules to SQLAlchemy 2.0 style.
  • Replace Session.query(...).first() with Session.scalar(select(...).limit(1)).
  • Replace Session.query(...).count() with Session.scalar(select(func.count()).select_from(...).where(...)).
  • Replace Session.query(...).all() with Session.scalars(select(...).where(...)).all().

Changes

Updated files

  • api/tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py
    • Added select and func imports.
    • Migrated document lookup and segment count assertions to SQLAlchemy 2.0 statement APIs.
  • api/tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py
    • Added select import.
    • Migrated segment reload query from query(...).all() to scalars(select(...)).all().

Related Issue

Replace remaining legacy Session.query patterns in document indexing integration tests with scalar/select and scalars(select(...)) to align with SQLAlchemy 2.x migration efforts.
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-14 07:15:26.946994580 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-14 07:15:16.270009008 +0000
@@ -1769,21 +1769,21 @@
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/tasks/test_disable_segment_from_index_task.py:64:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:53:20
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:54:20
 ERROR Object of class `Account` has no attribute `tenant_id` [missing-attribute]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:58:9
-ERROR Object of class `Account` has no attribute `type` [missing-attribute]
   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:59:9
+ERROR Object of class `Account` has no attribute `type` [missing-attribute]
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:60:9
 ERROR `Literal['owner']` is not assignable to attribute `role` with type `TenantAccountRole | None` [bad-assignment]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:60:24
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:61:24
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:70:20
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:71:20
 ERROR Object of class `Account` has no attribute `tenant_id` [missing-attribute]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:72:21
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:73:21
 ERROR Object of class `DatasetProcessRule` has no attribute `tenant_id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:233:9
+   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:234:9
 ERROR Object of class `DatasetProcessRule` has no attribute `updated_by` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:245:9
+   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:246:9
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/tasks/test_document_indexing_sync_task.py:33:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1797,9 +1797,9 @@
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:163:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:43:20
+  --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:44:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:48:53
+  --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:49:53
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:84:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-14 07:17:36.348315637 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-14 07:17:25.530402479 +0000
@@ -1769,21 +1769,21 @@
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/tasks/test_disable_segment_from_index_task.py:64:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:53:20
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:54:20
 ERROR Object of class `Account` has no attribute `tenant_id` [missing-attribute]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:58:9
-ERROR Object of class `Account` has no attribute `type` [missing-attribute]
   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:59:9
+ERROR Object of class `Account` has no attribute `type` [missing-attribute]
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:60:9
 ERROR `Literal['owner']` is not assignable to attribute `role` with type `TenantAccountRole | None` [bad-assignment]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:60:24
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:61:24
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:70:20
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:71:20
 ERROR Object of class `Account` has no attribute `tenant_id` [missing-attribute]
-  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:72:21
+  --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:73:21
 ERROR Object of class `DatasetProcessRule` has no attribute `tenant_id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:233:9
+   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:234:9
 ERROR Object of class `DatasetProcessRule` has no attribute `updated_by` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:245:9
+   --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:246:9
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/tasks/test_document_indexing_sync_task.py:33:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1797,9 +1797,9 @@
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:163:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:43:20
+  --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:44:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:48:53
+  --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:49:53
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:84:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 14, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 14, 2026
Merged via the queue into langgenius:main with commit a951cc9 Apr 14, 2026
30 checks passed
CodingOnStar pushed a commit that referenced this pull request Apr 14, 2026
…PI (#35145)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
HanqingZ pushed a commit to HanqingZ/dify that referenced this pull request Apr 23, 2026
…PI (langgenius#35145)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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 size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants