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

PlayerUsageUsage model fails to validate string-formatted numeric inputs #13

Open
AjJ132 opened this issue Oct 14, 2024 · 0 comments
Open

Comments

@AjJ132
Copy link

AjJ132 commented Oct 14, 2024

Issue Description

The PlayerUsageUsage model in the CFBD API client is currently unable to properly validate and parse numeric data returned as strings from the API. This results in validation errors when attempting to create PlayerUsageUsage objects from API responses.

Current Behavior

When the API returns numeric values as strings (e.g., "0.2935" instead of 0.2935), the PlayerUsageUsage model raises multiple validation errors, stating that the values are neither valid floats nor integers.

Expected Behavior

The PlayerUsageUsage model should be able to handle both numeric inputs and string-formatted numeric inputs, successfully parsing them into the appropriate float values.

Steps to Reproduce

  1. Make an API call that returns player usage data.
  2. Attempt to create a PlayerUsageUsage object from the returned data.
  3. Observe the validation errors.

Error Message

Traceback (most recent call last):
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\main.py", line 33, in
main()
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\main.py", line 30, in main
player_usage_extractor.extract_and_save_player_usage()
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\api\players\players.py", line 95, in extract_and_save_player_usage
players_usage = self.players_api.get_player_usage_with_http_info(year=year, team=test_team['school'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pydantic\decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
File "pydantic\decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
File "pydantic\decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\api\players_api.py", line 216, in get_player_usage_with_http_info
return self.api_client.call_api(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\api_client.py", line 435, in call_api
return_data = self.__call_api(*args)
^^^^^^^^^^^^^^^^^^^^^^
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\api_client.py", line 252, in __call_api
return_data = self.deserialize(response_data, response_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\api_client.py", line 327, in deserialize
return self.__deserialize(data, response_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\api_client.py", line 343, in __deserialize
return [self.__deserialize(sub_data, sub_kls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\api_client.py", line 366, in __deserialize
return self.__deserialize_model(data, klass)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\api_client.py", line 767, in __deserialize_model
return klass.from_dict(data)
^^^^^^^^^^^^^^^^^^^^^
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\models\player_usage.py", line 95, in from_dict
"usage": PlayerUsageUsage.from_dict(obj.get("usage")) if obj.get("usage") is not None else None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "R:\Projects\Athletic Department\Prototypes\CFBD API Saving\venv\Lib\site-packages\cfbd\models\player_usage_usage.py", line 75, in from_dict
_obj = PlayerUsageUsage.parse_obj({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pydantic\main.py", line 526, in pydantic.main.BaseModel.parse_obj
File "pydantic\main.py", line 341, in pydantic.main.BaseModel.init
pydantic.error_wrappers.ValidationError: 16 validation errors for PlayerUsageUsage
passingDowns
value is not a valid float (type=type_error.float)
passingDowns
value is not a valid integer (type=type_error.integer)
standardDowns
value is not a valid float (type=type_error.float)
standardDowns
value is not a valid integer (type=type_error.integer)
thirdDown
value is not a valid float (type=type_error.float)
thirdDown
value is not a valid integer (type=type_error.integer)
secondDown
value is not a valid float (type=type_error.float)
secondDown
value is not a valid integer (type=type_error.integer)
firstDown
value is not a valid float (type=type_error.float)
firstDown
value is not a valid integer (type=type_error.integer)
rush
value is not a valid float (type=type_error.float)
rush
value is not a valid integer (type=type_error.integer)
pass
value is not a valid float (type=type_error.float)
pass
value is not a valid integer (type=type_error.integer)
overall
value is not a valid float (type=type_error.float)
overall
value is not a valid integer (type=type_error.integer)

Environment

  • API version: 5.3.3
  • Package Version: 5.3.3a1
  • Generator Version: Generator version: 7.9.0
  • Python Version: 3.12.3

Potential Solution

A possible solution could involve adding a validator to the PlayerUsageUsage model that converts string inputs to floats before validation occurs. This would allow the model to handle both string and numeric inputs without breaking existing functionality.

Additional Context

This issue affects the usability of the API client, as it prevents users from properly parsing player usage data returned by the API. Resolving this would improve the robustness and reliability of the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant