refactor: extract duplicated request validators into core utilities#53
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
refactor: extract duplicated request validators into core utilities#53devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Consolidate the byte-identical non-negative-limit validator (6 copies) into core.models.NonNegativeLimit / RequiredNonNegativeLimit, and the optional-text validator (5 copies) into core.text.optional_text. Validation behavior and error messages are unchanged. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Two Pydantic field validators were copy-pasted across request/model modules. This folds them into
core/:Non-negative
limit— the same validator appeared 6 times (services/search,services/index,services/runs, and three inservices/viewer). Consolidated intocore.models:Fields become
limit: NonNegativeLimit = None/limit: RequiredNonNegativeLimit = 50, dropping the per-model@field_validator/@classmethodboilerplate.Optional-text — the
if value is None: return None; return required_text(...)pattern appeared 5 times (services/runs/models,workflows/build×2,workflows/garden,workflows/ingest). Consolidated intocore.text.optional_text(value, field_name); each validator now delegates in one line, preserving its per-model error label.Field-specific validators with distinct messages (
page_limit, transcript/filesystemsize, harnesscount/duration) were intentionally left alone — merging them would change error strings and over-abstract.Why
Reduce copy-paste and give these validators one home so behavior/wording stays consistent as new request types are added. Net −34 lines across 10 files.
Note: the per-source
errors.pyduplication (unavailable_runtime/first_error_line) was deliberately not touched —tests/test_architecture.pyenforces that split-by-responsibility layout.Verification
Also confirmed error messages/accept-reject behavior are byte-for-byte identical (negative limit → "limit must be non-negative"; required-int
limit=Nonestill rejected; empty title → "build request text must not be empty";Noneaccepted).Docs and wiki
Notes for reviewers
NonNegativeLimitkeeps the validator insideAnnotated[int | None, ...](rather thanAnnotated[int, ...] | None) so a single cleanValidationErroris produced — matching the previous@field_validatoroutput that surfaces viacli/execution.py.Link to Devin session: https://app.devin.ai/sessions/2ec4dbc36bd94d9da6e2b3e9ad796454
Requested by: @rohans0509