-
Notifications
You must be signed in to change notification settings - Fork 164
refactor(BA-4189): move out of convention session function into valid directory #8513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
0d22aec to
4eb146c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Refactors session-related helper utilities out of the API layer into the session service layer to prevent cyclic imports (api ↔ service) and better align module responsibilities.
Changes:
- Added
services/session/utils.pyand moveddrop_undefined()there. - Moved
overwritten_param_checkout ofapi/session.pyintoservices/session/types.py. - Updated
services/session/service.pyimports accordingly and removed the old helper definitions fromapi/session.py.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ai/backend/manager/services/session/utils.py | Introduces a service-layer utility module containing drop_undefined(). |
| src/ai/backend/manager/services/session/types.py | Hosts overwritten_param_check alongside existing session service dataclasses. |
| src/ai/backend/manager/services/session/service.py | Switches imports from API-layer helpers to service-layer helpers. |
| src/ai/backend/manager/api/session.py | Removes helper definitions/imports that were contributing to API↔service coupling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from ai.backend.common import validators as tx | ||
| from ai.backend.common.types import ClusterMode, SessionTypes | ||
| from ai.backend.manager.data.session.types import SessionStatus | ||
|
|
||
| overwritten_param_check = t.Dict({ |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
services/session/types.py now pulls in trafaret/validators just to host overwritten_param_check. In this codebase, service types.py files appear to be kept as lightweight dataclass/type holders (e.g. services/vfolder/types.py, services/image/types.py), and services/session/types.py is imported by action modules that only need the dataclasses. Consider moving overwritten_param_check into a dedicated module (e.g. services/session/validators.py or schemas.py) so non-validation callers don’t pay the extra import-time dependency/overhead.
| if isinstance(v, (Mapping, dict)): | ||
| newval = drop_undefined(dict(v)) | ||
| if len(newval.keys()) > 0: # exclude empty dict always |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In drop_undefined(), isinstance(v, (Mapping, dict)) is redundant because dict is already a Mapping, and len(newval.keys()) > 0 does extra work. You can simplify to check only Mapping and use a truthiness check (if newval) to avoid allocating the keys() view and computing its length.
| if isinstance(v, (Mapping, dict)): | |
| newval = drop_undefined(dict(v)) | |
| if len(newval.keys()) > 0: # exclude empty dict always | |
| if isinstance(v, Mapping): | |
| newval = drop_undefined(dict(v)) | |
| if newval: # exclude empty dict always |
resolves #8510 (BA-4189)
Move unnecessary functions which should not be located in api layer(not called from api but only from service) into service layer.
Checklist: (if applicable)
ai.backend.testdocsdirectory