OpenXbox / xbox-webapi-python

A python library to authenticate with Xbox Live via your Microsoft Account and provides Xbox related Web-API.
https://pypi.python.org/pypi/xbox-webapi
MIT License
175 stars 44 forks source link

Validation errors raised for batch presence #72

Closed GithubExo closed 1 year ago

GithubExo commented 2 years ago

Similar to #40 I got batch_presence call failing with

5 validation errors for PresenceBatchResponse
Root -> 25 -> lastSeen -> titleId
  field required (type=value_error.missing)
Root -> 236 -> lastSeen -> titleId
  field required (type=value_error.missing)
Root -> 297 -> lastSeen -> titleId
  field required (type=value_error.missing)
Root -> 797 -> lastSeen -> titleId
  field required (type=value_error.missing)
Root -> 985 -> lastSeen -> titleId
  field required (type=value_error.missing)

It seems some user presence response are missing the titleId field in the LastSeen item causing the whole batch to fail:

{
   "xuid":"2533274983196144",
   "state":"Offline",
   "lastSeen":{
      "deviceType":"Scarlett",
      "titleName":"",
      "timestamp":"2021-12-30T02:21:51.9177566Z"
   }
},
{
   "xuid":"2533274985813946",
   "state":"Offline",
   "lastSeen":{
      "deviceType":"Scarlett",
      "titleName":"",
      "timestamp":"2022-01-03T23:44:39.9942135Z"
   }
},
{
   "xuid":"2533274987396252",
   "state":"Offline",
   "lastSeen":{
      "deviceType":"Scarlett",
      "titleName":"",
      "timestamp":"2022-01-06T04:09:53.6234409Z"
   }
}

Should the LastSeen model title_id field be also edited to Optional[str]?

class LastSeen(CamelCaseModel):
    device_type: str
    title_id: Optional[str]
    title_name: str
    timestamp: str

This seems to fix the issue on my side.