Skip to content

Help with xbox_presence: Pydantic #102

Open

Description

@Sergio-Pedraza

when querying for some user batches, one may fail with an error like this:

1 validation error for PresenceBatchResponse 0.devices.0.titles.0.activity Input should be a valid list [type=list_type, input_value={'richPresence': 'Neptune: Story'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.5/v/list_type

I've done nothing but to provide a list of user ids to the xbl_client.presence.get_presence_batch method. There might be something in the validation or the responses that makes the whole batch invalid. Oddly enough, generally a few hours later the request executes successfully.

Activity

  1. tomballgithub commented on Jan 19, 2026

    @tomballgithub

    I am seeing the same error, but seemingly only once the account has transitioned from inactive to active.
    On the times where the account is active and it does consistently return presence correctly, the device type is 'iOS'
    It's all or nothing, once the account comes online, it either works every time or it doesn't

    Is there a known issue, fix, or method to debug?

    The command causing the error is:
    presence = await xbl_client.presence.get_presence(str(xuid), PresenceLevel.ALL)

    Example:
    1 validation error for PresenceItem devices.0.titles.1.activity Input should be a valid list [type=list_type, input_value={'richPresence': 'The City: The REC'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.11/v/list_type

    Here are the different 'Input should be a valid list' errors I've seen. 'The Theater: 0P 0R 0A' is by far the most prevalent.
    None of these are games that the user plays.

      Input should be a valid list [type=list_type, input_value={'richPresence': 'The City'}, input_type=dict]
      Input should be a valid list [type=list_type, input_value={'richPresence': 'The City: The REC'}, input_type=dict]
      Input should be a valid list [type=list_type, input_value={'richPresence': 'The City: The Theater'}, input_type=dict]
      Input should be a valid list [type=list_type, input_value={'richPresence': 'The Theater: 0P 0R 0A'}, input_type=dict]
    
  2. tomballgithub commented on Jan 21, 2026

    @tomballgithub

    I noticed that the response from Xbox does not give an error when it's like this:

    {
        'xuid': '2535468411947698',
        'state': 'Online',
        'devices': [{
                'type': 'Scarlett',
                'titles': [{
                        'id': '750323071',
                        'name': 'Home',
                        'placement': 'Background',
                        'state': 'Active',
                        'lastModified': '2026-01-20T22:32:36.7770783'
                    }, {
                        'id': '1870487792',
                        'name': 'NBA 2K26',
                        'placement': 'Full',
                        'state': 'Active',
                        'lastModified': '2026-01-20T22:32:36.7770783'
                    }
                ]
            }
        ]
    }
    

    but it does give an error when it's this:

    {
        'xuid': '2535468411947698',
        'state': 'Online',
        'devices': [{
                'type': 'Scarlett',
                'titles': [{
                        'id': '750323071',
                        'name': 'Home',
                        'placement': 'Background',
                        'state': 'Active',
                        'lastModified': '2026-01-20T22:32:36.7770783'
                    }, {
                        'id': '1870487792',
                        'activity': {
                            'richPresence': 'The City'
                        },
                        'name': 'NBA 2K26',
                        'placement': 'Full',
                        'state': 'Active',
                        'lastModified': '2026-01-20T22:33:22.3885066'
                    }
                ]
            }
        ]
    }
    

    The part that is causing the error is this:
    'activity': { 'richPresence': 'The City' },

    And if I change the last line to the following, removing the 'activity' section, it no longer fails:

            data = resp.json()
            # Iterate through each device
            for device in data.get('devices', []):
                # Iterate through each title in that device
                for title in device.get('titles', []):
                    # Remove 'activity' if it exists
                    title.pop('activity', None)
            json_string = json.dumps(data)
            return PresenceItem.model_validate_json(json_string)
    

    This pydantic check is the command causing the issue:
    PresenceItem.model_validate_json(json_string)

  3. tomballgithub commented on Jan 21, 2026

    @tomballgithub

    The fix is to edit \api\provider\presence\models.py from:
    activity: list[ActivityRecord] | None = None
    to
    activity: ActivityRecord | None = None

    The activity record is defined as being a dict rather than a list. The current code is looking for a list.
    https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/live/rest/json/json-titlerecord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions