Extract Behavior CRUD out of the crud/__init__.py monolith - #2455
Merged
Conversation
Move the six behavior functions out of crud/__init__.py into crud/behavior.py, following the split already done for tag, task, source and others. _BEHAVIOR_RELATED_FIELDS moves with them -- nothing else in __init__.py referenced it. Consumers import the module directly; nothing is re-exported. Nothing was dropped: all six functions still have callers. test_test_generation_pipeline.py patched the module-level `crud` name in test_generation_pipeline to stub get_behaviors, so those patch targets now point at `behavior_crud`.
This was referenced Aug 12, 2026
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 Behavior block out. Perapps/backend/AGENTS.mdthe package only shrinks from here — nothing new goes back into__init__.py.What Changed
get_behavior,get_behaviors,get_behaviors_detail,create_behavior,update_behavioranddelete_behaviorinto a newcrud/behavior.py(141 lines)._BEHAVIOR_RELATED_FIELDSmoved with them; nothing else in__init__.pyused it.crud/__init__.pydrops 118 lines.from rhesis.backend.app.crud import behavior as behavior_crud.get_behaviorhad a redundant function-localQueryBuilderimport; it is now module-level, matchingcrud/source.py._check_and_raise_if_deletedstays local, also matchingsource.py.get_behaviors_detailexists:get_behaviorsis a plainget_itemswith no eager loading, so the list endpoint calls the detail variant instead. That variant runs two queries — IDs first with filter/sort/limit, then an eager load scoped to those IDs — and re-applies the sort in Python becauseWHERE id IN (...)does not preserve order. Dropping that re-sort returns the right page in the wrong order with no error.Additional Context
crud/__init__.py, andgit merge-treeconfirms__init__.pymerges clean across all six pairings.services/test_config_generator.pyandservices/test_generation_pipeline.py. Both are the same trivial shape — each branch inserts its owncrudsubmodule import at the same spot, so the resolution is to keep both lines. Once both land, the last barecrud.use disappears from each 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.Testing
Pure move — behaviour is unchanged, so the existing suite is the check.
Ruff clean on all 7 touched files. A repo-wide grep for
crud.get_behavior,crud.get_behaviors,crud.get_behaviors_detail,crud.create_behavior,crud.update_behaviorandcrud.delete_behaviorreturns nothing.Worth a reviewer's eye:
tests/backend/services/test_test_generation_pipeline.pypatched the module-level name...test_generation_pipeline.crudand setcrud.get_behaviors.return_value. After the move that patch still applies cleanly but stubs nothing, so the tests would have reached a real DB call through aMagicMocksession and passed for the wrong reason. Retargeted tobehavior_crud.