Move QueryCondition/QueryOrder query primitives down from repositories.base to the models layer
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
Category E (largest): 83 files under models/**/conditions.py and models/**/orders.py import QueryCondition / QueryOrder from repositories.base (82 import statements) – models (DB layer) importing repositories (upper layer).
These are plain SQLAlchemy type aliases (QueryCondition = Callable[[], ColumnElement[bool]]; QueryOrder = UnaryExpression | ColumnElement) defined in repositories/base/types.py, not repository logic – they belong at or below the models layer.
Fix: move the two type aliases to a neutral lower location (e.g. models/base/types.py); have repositories.base re-export from there so existing repository imports keep resolving.
Out of scope: the BatchPurger/execute_batch_purger usage in models/vfolder/row.py – that is real repository logic in a model file and needs the opposite fix (move the orchestration up). Tracked as a separate sub-issue.
Success criteria:
- QueryCondition/QueryOrder defined at/below the models layer; no models/**/{conditions,orders}.py imports from repositories.**
- repositories continue to resolve the same symbols (re-export or direct import from the new location)
- pants check / lint / test pass for affected packages
JIRA Issue: BA-6608
Contributor guide
Research direction
Start with repositories/base/types.py and inspect the imports in models/**/conditions.py and models/**/orders.py, then identify the appropriate neutral models-layer location for the aliases. Preserve repository imports while removing the models-to-repositories dependency, leaving models/vfolder/row.py out of scope. Run pants check, lint, and tests for the affected packages to verify completion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlalchemy
- Domain
- backend, database
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 64/100