refactor: pass session as parameter in knowledge_retrieval_inner_service and agent_app_feature_service#37639
Conversation
…ice and agent_app_feature_service (langgenius#37403) Migrate db.session usage to explicit session parameter in two service files, following the pattern established in langgenius#37402. ### Changes - `knowledge_retrieval_inner_service.py`: - Added `session: scoped_session | None = None` to `retrieve()` - Added `session: scoped_session` to `_validate_caller_app()` and `_validate_datasets()` - Replaced `db.session` with `session` in validation methods - `agent_app_feature_service.py`: - Added `session: scoped_session | None = None` to `update_features()` - Replaced `db.session.add/flush/commit` with `session.add/flush/commit` - Controller callers updated to pass `session=db.session` explicitly. Closes langgenius#37403
Pyrefly Type Coverage
|
Head branch was pushed to by a user without write access
|
Thanks for the review @asukaminato0721! I've applied all four suggestions:
The callers already pass |
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-06-21 05:36:47.960388301 +0000
+++ /tmp/pyrefly_pr.txt 2026-06-21 05:36:33.433322587 +0000
@@ -6885,6 +6885,18 @@
--> tests/unit_tests/services/test_human_input_file_upload_service.py:55:20
ERROR `in` is not supported between `Literal['form_id=test-form']` and `None` [not-iterable]
--> tests/unit_tests/services/test_human_input_service.py:547:12
+ERROR Missing argument `session` in function `services.knowledge_retrieval_inner_service.InnerKnowledgeRetrievalService.retrieve` [missing-argument]
+ --> tests/unit_tests/services/test_knowledge_retrieval_inner_service.py:104:61
+ERROR Missing argument `session` in function `services.knowledge_retrieval_inner_service.InnerKnowledgeRetrievalService.retrieve` [missing-argument]
+ --> tests/unit_tests/services/test_knowledge_retrieval_inner_service.py:175:50
+ERROR Missing argument `session` in function `services.knowledge_retrieval_inner_service.InnerKnowledgeRetrievalService.retrieve` [missing-argument]
+ --> tests/unit_tests/services/test_knowledge_retrieval_inner_service.py:192:54
+ERROR Missing argument `session` in function `services.knowledge_retrieval_inner_service.InnerKnowledgeRetrievalService.retrieve` [missing-argument]
+ --> tests/unit_tests/services/test_knowledge_retrieval_inner_service.py:199:54
+ERROR Missing argument `session` in function `services.knowledge_retrieval_inner_service.InnerKnowledgeRetrievalService.retrieve` [missing-argument]
+ --> tests/unit_tests/services/test_knowledge_retrieval_inner_service.py:207:54
+ERROR Missing argument `session` in function `services.knowledge_retrieval_inner_service.InnerKnowledgeRetrievalService.retrieve` [missing-argument]
+ --> tests/unit_tests/services/test_knowledge_retrieval_inner_service.py:218:54
ERROR Object of class `ModelLoadBalancingService` has no attribute `provider_manager` [missing-attribute]
--> tests/unit_tests/services/test_model_load_balancing_service.py:76:5
ERROR Object of class `ModelLoadBalancingService` has no attribute `model_assembly` [missing-attribute]
|
|
=========================== short test summary info ============================ |
Address review feedback from asukaminato0721: - Remove '| None = None' from session parameter, make it required - Remove 'session = session or db.session' fallback lines - Callers already pass session=db.session explicitly
Head branch was pushed to by a user without write access
96f6aed to
abbaa7b
Compare
|
Thanks for the review @asukaminato0721! All 4 suggestions have been applied:
The session parameter is now required in both files, and the controller callers already pass |
|
Hi @asukaminato0721, thanks for the review suggestions! I've addressed the Since this batch1 PR already has lgtm, I kept it as-is to avoid rebasing. The style unification is in batch2. Let me know if you'd like me to backport the changes here instead! |
Summary
Migrate
db.sessionusage to explicitsessionparameter in two service files, following the pattern established in #37402.Changes
api/services/knowledge_retrieval_inner_service.py:session: scoped_session | None = Nonetoretrieve()session: scoped_sessionto_validate_caller_app()and_validate_datasets()db.sessionwithsessionin validation methodssession=db.sessionexplicitlyapi/services/agent_app_feature_service.py:session: scoped_session | None = Nonetoupdate_features()db.session.add/flush/commitwithsession.add/flush/commitsession=db.sessionexplicitlyPattern
This makes the session dependency explicit while maintaining backward compatibility via the default
Nonefallback.Related