fix(backend): restore ruff compliance across surfsense_backend - #1672
Conversation
The ruff pre-commit hooks run against every Python file a PR touches, so a lint violation that lands on dev is inherited by the next PR that edits the same file. `app/routes/documents_routes.py` is the live example: its import block is unsorted on dev, and PR MODSetter#1648 — which only appends a helper function far below the imports — has been failing Backend Quality on `ruff-check` because of it. `ruff check .` reported 21 violations on dev (339fe12): 19 I001, one RUF022, and one UP038. Twenty are `--fix` output. The UP038 is the one hand edit, `isinstance(cookies, (list, tuple))` to `isinstance(cookies, list | tuple)` in the Reddit fetcher, because ruff only offers it as an unsafe fix and the pinned hook runs a plain `--fix`; the two forms are equivalent on the project's Python 3.12 floor. `ruff format` covers eleven further files that had drifted. None of them overlap the files above, so each is pure whitespace. Every import move is alphabetical within its existing group — no import crosses a side-effect boundary, and the deliberately placed asyncio policy block in documents_routes.py is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CpY4T39RzhWyUV9qQpPWw7
|
@Yigtwxx is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…n check The pre-commit security scan runs detect-secrets over every file a PR touches. This branch only reorders imports in check_migration_flow.py, but that pulls the file into the scan and trips on its pre-existing localhost fallback DSN, which is not a real credential.
Summary
The
ruff/ruff-formatpre-commit hooks run against every Python file a PR touches, so a lint violation sitting ondevis inherited by the next PR that edits the same file — even when that PR did not go near the offending lines.This is not hypothetical. #1648 only appends a helper function near the bottom of
app/routes/documents_routes.py, and its Backend Quality has been red onruff-checksince it rebased onto currentdev:The error is in the import block that file already had:
What was wrong
Against
devat339fe12, using the version the hook pins (ruff-pre-commitv0.12.5):19
I001, oneRUF022, oneUP038, plus eleven files with format drift.Changes
Twenty violations are
ruff check --fixoutput, no hand edits — unsorted import blocks and one unsorted__all__.One hand edit.
UP038inapp/proprietary/platforms/reddit/fetch.py:159:isinstance(cookies, (list, tuple))becomesisinstance(cookies, list | tuple). Ruff only offers this as an unsafe fix and the hook runs a plain--fix, so it would stay red otherwise. The two forms are equivalent on the project's Python 3.12 floor.Eleven files reformatted by
ruff format. None of them overlap the files above, so every one of those hunks is pure whitespace.Every import move is alphabetical within its existing group. No import crosses a side-effect boundary, and the deliberately placed asyncio event-loop policy block in
documents_routes.py— the one with the# Force asyncio to use standard event loop before unstructured importscomment — is untouched.Testing
Clean on both, repo-wide, with the pinned version.
The four test files among the 21 are excluded by the hook's own
excludepattern, so they were never gating anything; they are included here soruff check .is clean as a whole rather than clean-except-where-nobody-looks.High-level PR Summary
This PR restores
rufflinter and formatter compliance across the entire backend codebase. It fixes 21 linting violations (20 import sorting issues and 1isinstancemodernization) and reformats 11 files with whitespace corrections. The changes were causing pre-commit hook failures for subsequent PRs that touched affected files, even when those PRs didn't introduce the violations. All fixes are automated tool output except for one hand-editedisinstancetype union syntax update to use Python 3.12's native|operator.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_backend/app/proprietary/platforms/reddit/fetch.pysurfsense_backend/app/knowledge_store/paths/__init__.pysurfsense_backend/alembic/env.pysurfsense_backend/app/agents/chat/multi_agent_chat/main_agent/middleware/kb_persistence/middleware.pysurfsense_backend/app/agents/chat/multi_agent_chat/main_agent/middleware/knowledge_tree/middleware.pysurfsense_backend/app/agents/chat/multi_agent_chat/shared/middleware/filesystem/backends/kb_postgres.pysurfsense_backend/app/agents/chat/multi_agent_chat/subagents/shared/run_reader.pysurfsense_backend/app/agents/chat/runtime/mention_resolver.pysurfsense_backend/app/knowledge_store/index/converge.pysurfsense_backend/app/knowledge_store/index/project.pysurfsense_backend/app/knowledge_store/index/rows.pysurfsense_backend/app/routes/documents_routes.pysurfsense_backend/app/services/folder_service.pysurfsense_backend/app/services/revert_service.pysurfsense_backend/app/tasks/celery_tasks/knowledge_store/index_tasks.pysurfsense_backend/scripts/check_migration_flow.pysurfsense_backend/scripts/migrate_knowledge_store.pysurfsense_backend/app/agents/chat/multi_agent_chat/main_agent/middleware/knowledge_store_persistence/commit_turn.pysurfsense_backend/app/knowledge_store/index/folders.pysurfsense_backend/app/knowledge_store/paths/resolve.pysurfsense_backend/app/knowledge_store/service.pysurfsense_backend/app/tasks/connector_indexers/local_folder_indexer.pysurfsense_backend/tests/integration/knowledge_store/index/test_converge.pysurfsense_backend/tests/integration/knowledge_store/index/test_project.pysurfsense_backend/tests/integration/knowledge_store/test_migrate.pysurfsense_backend/tests/integration/knowledge_store/test_migrate_placement.pysurfsense_backend/tests/integration/knowledge_store/test_path_column.pysurfsense_backend/tests/integration/knowledge_store/test_service.pysurfsense_backend/tests/integration/test_okf_path_identity.pysurfsense_backend/tests/unit/knowledge_store/test_recorded_virtual_path.pysurfsense_backend/tests/unit/middleware/test_git_tree_backend.pysurfsense_backend/tests/unit/services/test_model_connections.py