Repository navigation
Conversation
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-10-29 02:44:48.664773456 +0000
+++ /tmp/pyrefly_pr.txt 2026-10-29 02:44:38.376672764 +0000
@@ -166,6 +166,24 @@
--> tests/unit_tests/migrations/versions/test_2025_07_02_2332-1c9ba48be8e4_add_uuidv7_function_in_sql.py:31:46
ERROR Object of class `NoneType` has no attribute `loader` [missing-attribute]
--> tests/unit_tests/migrations/versions/test_2025_07_02_2332-1c9ba48be8e4_add_uuidv7_function_in_sql.py:32:5
+ERROR Could not find name `db` [unknown-name]
+ --> schedule/create_tidb_serverless_task.py:26:17
+ERROR Missing argument `session` in function `create_clusters` [missing-argument]
+ --> schedule/create_tidb_serverless_task.py:32:28
+ERROR Parse error: Expected a statement [parse-error]
+ --> schedule/create_tidb_serverless_task.py:34:13
+ERROR Parse error: Expected a statement [parse-error]
+ --> schedule/create_tidb_serverless_task.py:34:30
+ERROR Parse error: Expected an expression [parse-error]
+ --> schedule/create_tidb_serverless_task.py:34:35
+ERROR Parse error: Unexpected indentation [parse-error]
+ --> schedule/create_tidb_serverless_task.py:35:1
+ERROR `e` is uninitialized [unbound-name]
+ --> schedule/create_tidb_serverless_task.py:35:50
+ERROR Parse error: Expected `except` or `finally` after `try` block [parse-error]
+ --> schedule/create_tidb_serverless_task.py:38:5
+ERROR Could not find name `db` [unknown-name]
+ --> schedule/update_tidb_serverless_status_task.py:21:32
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `ConversationStatus | SQLCoreOperations[ConversationStatus]` in function `models.model.Conversation.__init__` [bad-argument-type]
--> tests/e2e_tests/containers/controllers/console/app/test_chat_conversation_status_count_api.py:75:16
ERROR Argument `Literal['app-run']` is not assignable to parameter `triggered_from` with type `SQLCoreOperations[WorkflowRunTriggeredFrom] | WorkflowRunTriggeredFrom` in function `models.workflow.WorkflowRun.__init__` [bad-argument-type]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (72.73%) is below the adjusted base coverage (88.54%). You can increase the head coverage or adjust the Removed Code Behavior. Additional details and impacted files@@ Coverage Diff @@
## main #41017 +/- ##
===========================================
- Coverage 89.54% 72.73% -16.82%
===========================================
Files 6011 5861 -150
Lines 377081 349771 -27310
Branches 76342 74598 -1744
===========================================
- Hits 337666 254397 -83269
- Misses 33421 91863 +58442
+ Partials 5994 3511 -2483
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
asukaminato0721
left a comment
There was a problem hiding this comment.
3 inline suggestions at f3676236be, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
| def test_create_clusters_persists_bindings_through_passed_session( | ||
| sqlite_session_factory: sessionmaker[Session], | ||
| ) -> None: | ||
| with patch.object( |
There was a problem hiding this comment.
This is an external boundary: define a small typing.Protocol for what the code needs, have the production code accept it as a parameter, and pass a fake that implements the Protocol in the test, instead of patching or mocking it.
dify-codereview · tests-real-dependencies (protocol-di) Learned from an earlier review. Reply here if this is wrong.
| TenantPluginAutoUpgradeStrategy.strategy_setting != TenantPluginAutoUpgradeStrategySetting.DISABLED, | ||
| ) | ||
| ).all() | ||
| with session_factory.create_session() as session: |
There was a problem hiding this comment.
Take the session as a required parameter instead of reaching for a global (@with_session injects it in controllers). If this code must open and commit its own short transaction, take the session factory as a parameter instead (e.g. in __init__). Then tests pass sqlite_session / sqlite_session_factory directly and need no monkeypatch, and can assert the committed row from another session instead of counting commits.
dify-codereview · inject-session Learned from an earlier review. Reply here if this is wrong.
| db.session.execute(delete(OAuthAccessToken).where(OAuthAccessToken.id.in_(ids))) | ||
| db.session.commit() | ||
| total += len(ids) | ||
| with session_factory.create_session() as session: |
There was a problem hiding this comment.
Take the session as a required parameter instead of reaching for a global (@with_session injects it in controllers). If this code must open and commit its own short transaction, take the session factory as a parameter instead (e.g. in __init__). Then tests pass sqlite_session / sqlite_session_factory directly and need no monkeypatch, and can assert the committed row from another session instead of counting commits.
dify-codereview · inject-session Learned from an earlier review. Reply here if this is wrong.
asukaminato0721
left a comment
There was a problem hiding this comment.
This branch has conflicts with main: please rebase onto the latest main. Checked f3676236be.
dify-codereview
Summary
Part of #37403.
Migrates the remaining scheduled tasks in
api/schedule/from the implicit globaldb.sessionto explicitly managed sessions, following the established patterns of this refactor: entry-point tasks open a session viasession_factory.create_session()(as inclean_unused_datasets_task.pyandmail_clean_document_notify_task.py), and helpers receive the session as a parameter (as in #37402).Changes:
create_tidb_serverless_task.py: task body opens an explicit session;create_clustersnow takessessionas a parameterupdate_tidb_serverless_status_task.py: query andupdate_clustersrun within one explicit session scopeclean_oauth_access_tokens_task.py: candidate selection, deletion and commit use an explicit sessionclean_embedding_cache_task.py: cleanup loop uses an explicit sessioncheck_upgradable_plugin_task.py: strategy query uses an explicit sessionqueue_monitor_task.py: removed the redundantfinally: db.session.close()block — this task performs no database work, and the app context pushed around every Celery task (FlaskTask.__call__inextensions/ext_celery.py) already removes the scoped session via Flask-SQLAlchemy teardownTests:
api/tests/unit_tests/schedule/with 10 SQLite-backed unit tests covering both cleanup tasks, both TiDB serverless tasks, and the plugin upgrade check taskVerified locally:
ruff format/check,pyrefly check(repo and tests configs),mypy, andlint-importsall clean; new tests pass 10/10.Screenshots
...
Checklist
make lintandmake type-checkFrom Claude Code