Skip to content

∴ Vector: Centralize display name validation using Pydantic Annotated#592

Draft
ToolchainLab wants to merge 1 commit into
mainfrom
vector/centralize-display-name-validation-9427188932183556861
Draft

∴ Vector: Centralize display name validation using Pydantic Annotated#592
ToolchainLab wants to merge 1 commit into
mainfrom
vector/centralize-display-name-validation-9427188932183556861

Conversation

@ToolchainLab

Copy link
Copy Markdown
Collaborator
  • 💡 What: Centralized duplicated display_name validation logic into a reusable Pydantic V2 type (DisplayNameStr using Annotated and BeforeValidator). Replaced repeated @field_validator methods in RegisterRequest and PasskeyRegisterStartRequest. Removed the unused _validate_display_name function.
  • 🎯 Why: To reduce duplication, establish a single source of truth for display name normalization/validation, and prevent future drift between models.
  • 🧠 Design: Created a pure normalization helper (normalize_display_name) that safely handles types before stripping. Wrapped this in a BeforeValidator within an Annotated type to create a composable validation primitive that perfectly replaces the scattered classmethods.
  • λ FP Angle: Transforms scattered, mutation-adjacent class methods into a declarative, type-driven pipeline. Semantics are now locked at the type level rather than repeatedly defined at the field level.
  • Verification: Ran uv run --locked ruff format . && uv run --locked ruff check . && uv run --locked mypy src && uv run pytest ensuring no behavior changes and that standard Pydantic validation errors still surface correctly for empty inputs.
  • 🧪 Edge cases: The new normalize_display_name correctly verifies isinstance(v, str) before mutating, allowing non-string inputs to safely fall through to Pydantic's built-in type validation.
  • ⚠️ Risk: Extremely low. The behavior is identical to the previous @field_validator implementations, and standard test coverage confirms schemas correctly reject whitespace-only names.

PR created automatically by Jules for task 9427188932183556861 started by @ToolchainLab

Extracted duplicated whitespace stripping and empty-string validation for
display names into a reusable `DisplayNameStr` type using Pydantic V2's
`Annotated` and `BeforeValidator`. Replaced repeated `@field_validator`
methods across `RegisterRequest` and `PasskeyRegisterStartRequest`.
Removed unused `_validate_display_name` function.

Co-authored-by: ToolchainLab <263750431+ToolchainLab@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant