Automated Action b3cbb43878 Fix email validation dependency issue
- Added email-validator package to requirements.txt
- Modified user schema to provide fallback if email-validator is not available
- This fixes the health check failure due to missing email-validator dependency
2025-05-27 20:39:37 +00:00

61 lines
1.6 KiB
Python

from datetime import datetime
from typing import Optional
# Try to import EmailStr from pydantic, and provide a fallback if email-validator is not available
try:
from pydantic import BaseModel, EmailStr, Field
except ImportError:
from pydantic import BaseModel, Field
# Define a basic EmailStr replacement that accepts strings but doesn't validate them
# This will be used only if email-validator is not installed
from pydantic.types import StringType
class EmailStr(StringType):
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, v):
if not isinstance(v, str):
raise ValueError('string required')
return v
class UserBase(BaseModel):
"""Base schema for user information."""
email: EmailStr
username: str
is_active: Optional[bool] = True
class UserCreate(UserBase):
"""Schema for creating a new user."""
password: str = Field(..., min_length=8)
class UserUpdate(BaseModel):
"""Schema for updating an existing user."""
email: Optional[EmailStr] = None
username: Optional[str] = None
password: Optional[str] = Field(None, min_length=8)
is_active: Optional[bool] = None
class UserInDBBase(UserBase):
"""Base schema for user with DB fields."""
id: int
created_at: datetime
updated_at: Optional[datetime] = None
class Config:
from_attributes = True
class User(UserInDBBase):
"""Schema for user response data (no password)."""
pass
class UserInDB(UserInDBBase):
"""Schema for user in DB (includes password)."""
hashed_password: str