Skip to content

refactor: for db.session feedback service.export feedbacks - #37763

Merged
asukaminato0721 merged 5 commits into
langgenius:mainfrom
Kunal152000:refactor_for_db.session_FeedbackService.export_feedbacks
Jun 23, 2026
Merged

asukaminato0721 merged 5 commits into
langgenius:mainfrom
Kunal152000:refactor_for_db.session_FeedbackService.export_feedbacks

Conversation

@Kunal152000

@Kunal152000 Kunal152000 commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refactors MetadataService to accept the database session as an explicit parameter instead of relying on the global, context-local db.session. This is part of the incremental effort under #37403 to decouple core service layers from Flask-SQLAlchemy's global session registry, which improves test isolation and makes each method's data-access dependency explicit.

What changed

  • api/services/metadata_service.py: added session: Session as the first positional parameter to the 7 methods that touch the database (create_metadata, update_metadata_name, delete_metadata, enable_built_in_field, disable_built_in_field, update_documents_metadata, get_dataset_metadatas) and replaced every db.session.* call with session.*. The db import is removed; get_built_in_fields and knowledge_base_metadata_lock_check are unchanged (no DB access).
  • Controllers now pass db.session() explicitly:
    api/controllers/console/datasets/metadata.py and api/controllers/service_api/dataset/metadata.py.
  • Tests updated to pass the session directly: the container Session fixture for the integration tests, and a Mock() for the early-validation unit tests.
    The commit-failure test now patches the passed session (patch.object(db_session_with_containers, "commit", ...)) instead of the global db.session.commit.

Convention

Follows the merged TagService refactor: session: Session as the first positional argument, callers pass db.session(). No behavior change — this is a pure, behavior-preserving refactor.

Part of #37403 (incremental; intentionally not using Fixes since the umbrella
issue spans many services).

Screenshots

N/A (backend refactor, no UI changes).

Screenshots

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 && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. refactor labels Jun 22, 2026
@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-06-23 13:03:22.228555402 +0000
+++ /tmp/pyrefly_pr.txt	2026-06-23 13:03:11.587487193 +0000
@@ -1224,6 +1224,10 @@
     --> tests/test_containers_integration_tests/services/test_feature_service.py:1871:16
 ERROR Object of class `NoneType` has no attribute `limit` [missing-attribute]
     --> tests/test_containers_integration_tests/services/test_feature_service.py:1872:16
+ERROR Multiple values for argument `app_id` in function `services.feedback_service.FeedbackService.export_feedbacks` [bad-keyword-argument]
+   --> tests/test_containers_integration_tests/services/test_feedback_service.py:165:13
+ERROR Multiple values for argument `app_id` in function `services.feedback_service.FeedbackService.export_feedbacks` [bad-keyword-argument]
+   --> tests/test_containers_integration_tests/services/test_feedback_service.py:218:17
 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/services/test_file_service.py:69: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]
@@ -2049,57 +2053,57 @@
 ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
  --> tests/unit_tests/controllers/common/test_fields.py:9:5
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account` in function `controllers.console.app.completion._create_chat_message` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1223:74
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1170:74
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.completion._create_chat_message` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1223:98
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1170:98
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account` in function `controllers.console.app.completion._create_chat_message` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1260:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1207:30
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.completion._create_chat_message` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1261:27
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1208:27
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account` in function `controllers.console.app.completion._resolve_current_user_agent_debug_conversation_id` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1288:22
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1235:22
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.completion._resolve_current_user_agent_debug_conversation_id` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1289:19
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1236:19
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account` in function `controllers.console.app.completion._resolve_current_user_agent_debug_conversation_id` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1294:22
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1241:22
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.completion._resolve_current_user_agent_debug_conversation_id` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1295:19
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1242:19
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account` in function `controllers.console.app.completion._create_chat_message` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1346:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1293:30
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.completion._create_chat_message` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1347:27
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1294:27
 ERROR Object of class `object` has no attribute `data` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1429:50
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1376:50
 ERROR Object of class `object` has no attribute `limit` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1430:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1377:30
 ERROR Object of class `object` has no attribute `has_more` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1431:33
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1378:33
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.message._list_chat_messages` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1443:67
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1390:67
 ERROR Object of class `object` has no attribute `data` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1469:50
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1416:50
 ERROR Object of class `object` has no attribute `limit` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1470:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1417:30
 ERROR Object of class `object` has no attribute `has_more` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1471:33
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1418:33
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.message._list_chat_messages` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1485:67
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1432:67
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account | None` in function `controllers.console.app.message._list_chat_messages` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1485:91
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1432:91
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.message._list_chat_messages` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1505:27
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1452:27
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account | None` in function `controllers.console.app.message._list_chat_messages` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1506:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1453:30
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account` in function `controllers.console.app.message._update_message_feedback` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1521:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1468:30
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.message._update_message_feedback` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1522:27
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1469:27
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account` in function `controllers.console.app.message._get_message_suggested_questions` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1558:26
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1505:26
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.message._get_message_suggested_questions` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1559:23
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1506:23
 ERROR Argument `Literal['00000000-0000-0000-0000-000000000002']` is not assignable to parameter `message_id` with type `UUID` in function `controllers.console.app.message._get_message_suggested_questions` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1560:24
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1507:24
 ERROR Object of class `int` has no attribute `lower` [missing-attribute]
    --> tests/unit_tests/controllers/console/app/test_annotation_security.py:221:38
 ERROR Object of class `int` has no attribute `lower` [missing-attribute]
@@ -6485,53 +6489,43 @@
 ERROR Argument `list[SimpleNamespace]` is not assignable to parameter `recipients` with type `Sequence[HumanInputFormRecipient]` in function `repositories.sqlalchemy_api_workflow_run_repository._build_human_input_required_reason` [bad-argument-type]
   --> tests/unit_tests/repositories/test_sqlalchemy_api_workflow_run_repository.py:56:9
 ERROR Object of class `object` has no attribute `prompt` [missing-attribute]
-   --> tests/unit_tests/services/agent/test_agent_services.py:665:12
-ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/services/agent/test_agent_services.py:841:12
-ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/services/agent/test_agent_services.py:842:12
-ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/services/agent/test_agent_services.py:843:12
-ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/services/agent/test_agent_services.py:845:12
-ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/services/agent/test_agent_services.py:846:12
+   --> tests/unit_tests/services/agent/test_agent_services.py:632:12
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `scoped_session[Unknown]` in function `services.app_service.AppService._build_app_list_filters` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:1863:61
+    --> tests/unit_tests/services/agent/test_agent_services.py:1408:61
 ERROR Object of class `object` has no attribute `name` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2337:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:1882:16
 ERROR Object of class `object` has no attribute `mode` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2338:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:1883:16
 ERROR Object of class `object` has no attribute `agent_role` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2339:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:1884:16
 ERROR Object of class `object` has no attribute `agent_role` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2415:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:1960:16
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.validate_agent_nodes_for_publish` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2624:25
+    --> tests/unit_tests/services/agent/test_agent_services.py:2169:25
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.validate_agent_nodes_for_publish` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2646:25
+    --> tests/unit_tests/services/agent/test_agent_services.py:2191:25
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.project_draft_bindings_to_graph` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2710:21
+    --> tests/unit_tests/services/agent/test_agent_services.py:2255:21
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_roster_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2769:21
+    --> tests/unit_tests/services/agent/test_agent_services.py:2314:21
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2838:21
+    --> tests/unit_tests/services/agent/test_agent_services.py:2383:21
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2893:25
+    --> tests/unit_tests/services/agent/test_agent_services.py:2438:25
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2925:25
+    --> tests/unit_tests/services/agent/test_agent_services.py:2470:25
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2957:25
+    --> tests/unit_tests/services/agent/test_agent_services.py:2502:25
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:3003:25
+    --> tests/unit_tests/services/agent/test_agent_services.py:2548:25
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_roster_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:3063:21
+    --> tests/unit_tests/services/agent/test_agent_services.py:2608:21
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_roster_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:3133:21
+    --> tests/unit_tests/services/agent/test_agent_services.py:2678:21
 ERROR Argument `FakeSession` is not assignable to parameter `session` with type `Session` in function `services.agent.workflow_publish_service.WorkflowAgentPublishService.sync_roster_agent_bindings_for_draft` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:3166:21
+    --> tests/unit_tests/services/agent/test_agent_services.py:2711:21
 ERROR Cannot set item in `dict[str, str]` [unsupported-operation]
-    --> tests/unit_tests/services/agent/test_agent_services.py:3412:31
+    --> tests/unit_tests/services/agent/test_agent_services.py:2957:31
 ERROR Object of class `NoneType` has no attribute `workflow_prompt` [missing-attribute]
    --> tests/unit_tests/services/agent/test_composer_mention_validation.py:113:5
 ERROR Class member `ConcreteApiKeyAuth.validate_credentials` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]

@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 50.91% 50.91% +0.01%
Strict coverage 50.42% 50.42% +0.01%
Typed symbols 30,192 30,199 +7
Untyped symbols 29,399 29,399 0
Modules 2928 2928 0

@asukaminato0721

Copy link
Copy Markdown
Contributor

fix ci

@Kunal152000 Kunal152000 changed the title Refactor for db.session feedback service.export feedbacks refactor: for db.session feedback service.export feedbacks Jun 23, 2026
@Kunal152000
Kunal152000 force-pushed the refactor_for_db.session_FeedbackService.export_feedbacks branch from 843b3e0 to 5ad9a0a Compare June 23, 2026 07:10
@Kunal152000

Copy link
Copy Markdown
Contributor Author

@asukaminato0721

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 23, 2026
@asukaminato0721

Copy link
Copy Markdown
Contributor

fix ci

@asukaminato0721 asukaminato0721 self-assigned this Jun 23, 2026
auto-merge was automatically disabled June 23, 2026 12:02

Head branch was pushed to by a user without write access

@asukaminato0721

Copy link
Copy Markdown
Contributor

fix ci

Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
@asukaminato0721
asukaminato0721 self-requested a review June 23, 2026 13:46
@asukaminato0721
asukaminato0721 added this pull request to the merge queue Jun 23, 2026
Merged via the queue into langgenius:main with commit 5b45306 Jun 23, 2026
31 checks passed
Ssazurov pushed a commit to Ssazurov/dify that referenced this pull request Aug 8, 2026
…s#37763)

Co-authored-by: kunalj1-arch <kunal.j1@turing.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants