[ModelDeploy] Guard the preset-derived replica count and strategy fallbacks
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 368
Description
## Goal
Close two unguarded fallbacks in `DeploymentController._apply_deployment_level_preset` that are safe only by accident.
## Background
Both are in `sokovan/deployment/deployment_controller.py`, on the path every preset-driven deploy takes.
**Null replica count.** `:773-780` reads the preset's replica count with no null check:
```python
preset_replica = preset_data.replica_count if preset_data is not None else self._DEFAULT_REPLICA_COUNT
resolved_replica_spec = ReplicaSpec(replica_count=preset_replica)
```
The `open_to_public` fallback immediately below (`:782-789`) does guard with `is not None` and falls through to the system default. The replica branch only survives because `DeploymentRevisionPresetData.replica_count` is a non-optional `int` today; the asymmetry means the intent is not enforced, and a null would reach `endpoints.replicas` as an integrity error at insert time.
**Non-exhaustive strategy match.** `_build_policy_from_preset` (`:803-824`) matches `DeploymentStrategy.ROLLING` and `BLUE_GREEN` with no fallback arm, so `strategy_spec` would be unbound if `deployment_strategy` ever became nullable or gained a member. The failure mode is an `UnboundLocalError`, not a domain error.
Neither is reachable today. Both are one-line fixes and both sit on the code path this epic is already touching.
## Acceptance Criteria
- The replica fallback chain is explicit: caller input, then preset value when present, then `_DEFAULT_REPLICA_COUNT` — matching the shape of the `open_to_public` branch beside it.
- `_build_policy_from_preset` handles every `DeploymentStrategy` member, with any unhandled case surfacing as a domain error rather than an `UnboundLocalError`.
JIRA Issue: BA-XXXX
Contributor guide
Research direction
Start in sokovan/deployment/deployment_controller.py and read _apply_deployment_level_preset alongside the guarded open_to_public fallback. Then inspect _build_policy_from_preset and the DeploymentStrategy members; done means the replica fallback reaches _DEFAULT_REPLICA_COUNT when needed and every strategy path produces a domain error rather than an unbound variable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100