python.pydantic.arbitrary_types
Correctness
Medium
Detects Pydantic models using arbitrary_types_allowed without proper validation.
Why It Matters
Section titled “Why It Matters”Arbitrary types without validation:
- No type checking — Complex types not validated
- Serialization errors — Can’t convert to JSON
- Hidden bugs — Invalid data passes silently
Example
Section titled “Example”# ❌ Before (arbitrary types without validators)from pydantic import BaseModel
class MyModel(BaseModel): class Config: arbitrary_types_allowed = True
db_connection: Connection # No validation!# ✅ After (with custom validator)from pydantic import BaseModel, validator
class MyModel(BaseModel): class Config: arbitrary_types_allowed = True
db_connection: Connection
@validator('db_connection') def validate_connection(cls, v): if not v.is_connected: raise ValueError('Connection must be active') return vWhat Unfault Detects
Section titled “What Unfault Detects”- arbitrary_types_allowed without validators
- Complex types without serialization logic
- Missing get_validators implementations