Extract File CRUD out of the crud/__init__.py monolith - #2456
Merged
Conversation
Move the seven file functions out of crud/__init__.py into crud/file.py, following the split already done for comment, token, metric and others. Consumers import the module directly; nothing is re-exported. All seven have callers, so nothing was dropped. Removing the block left func unused at module scope in crud/__init__.py, which turned the local "from sqlalchemy import func" inside get_user_by_email into an F811, so the module-level import of func goes too. telemetry.py and routers/file.py no longer need "from rhesis.backend.app import crud" at all; tracing.py and conversation_linking.py swap their function-local "crud as _crud" imports for the file module.
This was referenced Aug 12, 2026
|
Looks good. Clean extraction into |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
crud/__init__.pyis a 1946-line monolith that the codebase is splitting one entity at a time, following #2411, #2412, #2438, #2439, #2441, #2442, #2449, #2450 and #2451. This takes the File block out. Perapps/backend/AGENTS.mdthe package only shrinks from here — nothing new goes back into__init__.py.What Changed
create_file,get_file,link_file_to_entity,get_files_for_entity,get_entity_files_total_size,get_entity_files_max_positionanddelete_fileinto a newcrud/file.py(151 lines), unchanged. The# File CRUD operationsbanner in__init__.pygoes with them.crud/__init__.pydrops 121 lines.from rhesis.backend.app.crud import file as file_crud.routers/telemetry.pyandrouters/file.pyno longer needfrom rhesis.backend.app import crudat all.services/invokers/tracing.pyandservices/telemetry/conversation_linking.pyhad function-localfrom rhesis.backend.app import crud as _crudimports, now direct submodule imports.funcwith no module-scope use in__init__.py, which turned the pre-existing function-localfrom sqlalchemy import funcinsideget_user_by_emailinto a ruffF811.funcis therefore dropped from the top-levelfrom sqlalchemy import and_, func, select, text.and_,selectandtextare still used.Additional Context
crud/__init__.py, andgit merge-treeconfirms__init__.pymerges clean across all six pairings — including thefuncimport change above.get_test_setsandget_tests, which Add metric tuning for custom metrics [feature branch] #2446 modifies.Testing
Pure move — behaviour is unchanged, so the existing suite is the check.
Skips are pre-existing
@pytest.mark.skips. A repo-wide grep acrossapps/,tests/,sdk/,ee/,packages/andpenelope/for the seven oldcrud.*names returns nothing, and there is nogetattr(crud, ...)/hasattr(crud, ...)reflection anywhere that could reach them dynamically.Two pre-existing ruff findings remain in
routers/test_result.py(I001, and unusedtyping.Optional). Both were confirmed against a stashed baseline and left alone rather than mixed into this refactor.Worth a reviewer's eye: the two file test modules patch by module attribute, so
"...results.crud"became"...results.file_crud"andmock_crudbecamemock_file_crud. Left unchanged these would have failed loudly onassert_called_once()rather than silently passing.