fix: use Annotated+BeforeValidator for webhook secret normalization
The previous field_validator approach passed `cls` as the first argument to `_normalize_secret`, which only accepted `v`, causing a TypeError at runtime. Switch to `Annotated[str | None, BeforeValidator(...)]` which calls the function with just the value and also eliminates the repeated validator assignment in both schema classes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Abhimanyu Saharan
parent
2ef6164cf8
commit
433021b02c
@@ -3,9 +3,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Annotated
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import field_validator
|
||||
from pydantic import BeforeValidator
|
||||
from sqlmodel import SQLModel
|
||||
|
||||
from app.schemas.common import NonEmptyStr
|
||||
@@ -21,15 +22,16 @@ def _normalize_secret(v: str | None) -> str | None:
|
||||
return stripped or None
|
||||
|
||||
|
||||
NormalizedSecret = Annotated[str | None, BeforeValidator(_normalize_secret)]
|
||||
|
||||
|
||||
class BoardWebhookCreate(SQLModel):
|
||||
"""Payload for creating a board webhook."""
|
||||
|
||||
description: NonEmptyStr
|
||||
enabled: bool = True
|
||||
agent_id: UUID | None = None
|
||||
secret: str | None = None
|
||||
|
||||
_normalize_secret = field_validator("secret", mode="before")(_normalize_secret)
|
||||
secret: NormalizedSecret = None
|
||||
|
||||
|
||||
class BoardWebhookUpdate(SQLModel):
|
||||
@@ -38,9 +40,7 @@ class BoardWebhookUpdate(SQLModel):
|
||||
description: NonEmptyStr | None = None
|
||||
enabled: bool | None = None
|
||||
agent_id: UUID | None = None
|
||||
secret: str | None = None
|
||||
|
||||
_normalize_secret = field_validator("secret", mode="before")(_normalize_secret)
|
||||
secret: NormalizedSecret = None
|
||||
|
||||
|
||||
class BoardWebhookRead(SQLModel):
|
||||
|
||||
Reference in New Issue
Block a user