Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix PlayerUsageUsage validation for string inputs
  • Loading branch information
AjJ132 committed Oct 14, 2024
commit 9d58b077eec4f624f7ebfbdb41354e05bce28ab0
12 changes: 11 additions & 1 deletion cfbd/models/player_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@



from pydantic import BaseModel, Field, StrictInt, StrictStr
from pydantic import BaseModel, Field, StrictInt, StrictStr, validator
from cfbd.models.player_usage_usage import PlayerUsageUsage

class PlayerUsage(BaseModel):
Expand All @@ -41,6 +41,16 @@ class Config:
allow_population_by_field_name = True
validate_assignment = True


@validator('*', pre=True)
def convert_string_to_float(cls, v):
if isinstance(v, str):
try:
return float(v)
except ValueError:
raise ValueError(f"Cannot convert {v} to float")
return v

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))
Expand Down