Commit 139acc4
refactor(BA-5983): defer default-value application to strict Pydantic types
``ModelHealthCheckDraft.to_resolved`` and
``ModelServiceConfigDraft.to_resolved`` previously duplicated every
default value (``10.0``, ``10``, ``15.0``, ``200``, ``60.0`` for the
health-check fields; ``[]`` and ``"/bin/bash"`` for the service
config) inline as ``if self.x is not None else <default>`` branches.
Those literals were already declared on the strict ``ModelHealthCheck``
/ ``ModelServiceConfig`` classes via ``Field(default=...)``, so the
project carried the same constants in two places at risk of drift.
Switch ``to_resolved`` to drop ``None`` scalars via
``model_dump(exclude_none=True)`` and let the strict type's field
defaults apply during ``model_validate``/constructor call. Required-
field checks (``path``, ``port``) stay as explicit ``ValueError``
raises so the error message remains domain-specific rather than a
generic ``pydantic.ValidationError``. The nested ``health_check``
draft is resolved out-of-band before the strict service config is
composed, since it carries its own required-field check.
Behavior-preserving:
- Every ``Field(default=...)`` on the strict type matches the
literal the old code wrote inline (verified field-by-field).
- ``pre_start_actions``: old ``or []`` and new ``exclude_none=True``
produce identical results for the two reachable shapes (``None``
and ``list[PreStartAction]``).
- Field-level constraints (``gt``, ``ge``) still fire because both
the old constructor call and the new ``model_validate`` execute
Pydantic validators.
Existing tests in test_config / test_revision_draft_merge /
test_model_definition_start_command_compat / test_revision_draft_reader
still pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8366021 commit 139acc4
1 file changed
Lines changed: 9 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
547 | 540 | | |
548 | 541 | | |
549 | 542 | | |
| |||
561 | 554 | | |
562 | 555 | | |
563 | 556 | | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
564 | 561 | | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
| 562 | + | |
| 563 | + | |
570 | 564 | | |
571 | 565 | | |
572 | 566 | | |
| |||
0 commit comments