tybug / ossapi

The definitive python wrapper for the osu! api.
https://tybug.github.io/ossapi/
GNU Affero General Public License v3.0
80 stars 17 forks source link

best_id with null values #22

Closed nwxnk closed 3 years ago

nwxnk commented 3 years ago

best_id is denoted as a non-optional field, on the osu!web Documentation page. But not having it as an optional field causes the _resolve_annotations function to raise an exception as it always expects best_id to be a valid integer.

>>> api = ossapi.Osapi = ossapi.OssapiV2(client_id, client_secret, redirect_uri)
>>> api.log.setLevel('DEBUG')
>>>
>>> api.user_scores(8945180, ossapi.ScoreType.RECENT)[0]
made request to https://osu.ppy.sh/api/v2/users/8945180/scores/recent
received json: https://pastebin.com/raw/FVFGAYnY
instantiating type <class 'ossapi.models.Score'>
ignoring unexpected parameter `passed` from api response for type <class 'ossapi.models.Score'>
resolving [...]
resolved  [...]
Score(...)
>>>
>>>
>>> api.user_scores(14644448, ossapi.ScoreType.RECENT)
made request to https://osu.ppy.sh/api/v2/users/14644448/scores/recent
received json: https://pastebin.com/raw/aPEH44RQ
instantiating type <class 'ossapi.models.Score'>
ignoring unexpected parameter `passed` from api response for type <class 'ossapi.models.Score'>
resolving annotations for type <class 'ossapi.models.Score'>
resolving attribute id
resolving attribute best_id
<class 'int'> None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\nwxnk\AppData\Roaming\Python\Python39\site-packages\ossapi\ossapiv2.py", line 83, in wrapper
    return function(*args, **kwargs)
  File "C:\Users\nwxnk\AppData\Roaming\Python\Python39\site-packages\ossapi\ossapiv2.py", line 682, in user_scores
    return self._get(List[Score], f"/users/{user_id}/scores/{type_.value}",
  File "C:\Users\nwxnk\AppData\Roaming\Python\Python39\site-packages\ossapi\ossapiv2.py", line 213, in _get
    return self._instantiate_type(type_, json_)
  File "C:\Users\nwxnk\AppData\Roaming\Python\Python39\site-packages\ossapi\ossapiv2.py", line 370, in _instantiate_type
    entry = self._resolve_annotations(entry)
  File "C:\Users\nwxnk\AppData\Roaming\Python\Python39\site-packages\ossapi\ossapiv2.py", line 305, in _resolve_annotations
    value = self._instantiate_type(type_, value, obj, attr_name=attr)
  File "C:\Users\nwxnk\AppData\Roaming\Python\Python39\site-packages\ossapi\ossapiv2.py", line 335, in _instantiate_type
    raise TypeError(f"expected type {type_} for value {value}, got "
TypeError: expected type <class 'int'> for value None, got type <class 'NoneType'> (for attribute: best_id)
tybug commented 3 years ago

not sure why they've changed this, but looks to be intentional on their end. Just going to mark it optional and call it a day (9d02feac0e7acdb96765973716d78a169a2776f2). Thanks for the report