Extract Model CRUD out of the crud/__init__.py monolith - #2457
Merged
Conversation
This was referenced Aug 12, 2026
|
Looks good. Clean extraction of the model CRUD into |
Move the model functions out of crud/__init__.py into crud/model.py,
following the split already done for source, task, tag and others.
Consumers import the module directly; nothing is re-exported.
Drops test_model_connection, a stub that only ever returned True and had
no callers -- the /models/{id}/test endpoint uses ModelConnectionService
instead.
routers/services.py already aliased the whole crud package as
model_crud; it now aliases the submodule under the same name.
akwasigroch
force-pushed
the
refactor/extract-model-crud
branch
from
August 12, 2026 15:23
2023b7a to
a6187cc
Compare
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 Model block out. Perapps/backend/AGENTS.mdthe package only shrinks from here — nothing new goes back into__init__.py.What Changed
get_model,get_models,create_model,update_modelanddelete_modelinto a newcrud/model.py(149 lines), byte-for-byte. The internal coupling stays inside the new module:update_modelanddelete_modelboth callget_model.crud/__init__.pydrops 142 lines. The Tool block directly below is untouched.from rhesis.backend.app.crud import model as model_crud. The alias matters here — many of these modules already importmodels, andmodel/modelsis easy to confuse.test_model_connection. Zero callers repo-wide. The/models/{id}/testendpoint has its own asynctest_model_connectioninrouters/model.pybacked byModelConnectionService; the crud version was a stub whose entire body wasreturn Trueinside atrythat could never raise. Dead code that read as live because a real function shares its name.is_protectedsystem-model rules, since they are enforced across two functions and are easy to miss: protected models reject edits toname,model_name,provider_type_id,key,endpoint,is_protectedandicon, and reject deletion outright, while tags, status, owner and assignee stay editable.Additional Context
crud/__init__.py, andgit merge-treeconfirms__init__.pymerges clean across all six pairings.services/test_config_generator.pyandservices/test_generation_pipeline.py, and with User inservices/explorer/embeddings.pyandutils/user_model_utils.py. All four are the same trivial shape — each branch inserts its owncrudsubmodule import at the same spot, so the resolution is to keep both lines. Once each pair lands, the last barecrud.use disappears from that file and thefrom rhesis.backend.app import crudimport must be dropped (ruffF401).get_test_setsandget_tests, which Add metric tuning for custom metrics [feature branch] #2446 modifies. Kept as a pure move so Rename Rhesis Default model to Rhesis #2385 (Rhesis Default model rename) rebases cleanly.Testing
Pure move plus one dead-function deletion, so the existing suite is the check.
Ruff clean on all 13 touched files. A repo-wide grep for the six old
crud.*names returns nothing.Two things worth a reviewer's eye:
routers/services.pywas already using the namemodel_crud, but bound to the wholecrudpackage rather than a submodule — exactly the reach-through patternapps/backend/AGENTS.mdwarns about, which only worked because the alias happened to resolveget_modeloff the monolith. It now points at the real submodule.get_modelcollides three ways in this area: this crud function, the SDK factoryrhesis.sdk.models.factory.get_model, and the router endpoint.utils/user_model_utils.pyimports both the SDK factory andmodel_crud, andtests/backend/utils/test_llm_delegation.pydeliberately patches both...user_model_utils.get_model(SDK) and...user_model_utils.model_crud.get_model(crud).