Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PlayerUsageUsage validation for string inputs and hireDate null value handling for coaches #14

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cfbd/models/coach.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Coach(BaseModel):
"""
first_name: StrictStr = Field(default=..., alias="firstName")
last_name: StrictStr = Field(default=..., alias="lastName")
hire_date: Optional[datetime] = Field(default=..., alias="hireDate")
hire_date: Optional[str] = Field(default=None, alias="hireDate")
seasons: conlist(CoachSeason) = Field(...)
__properties = ["firstName", "lastName", "hireDate", "seasons"]

Expand Down
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