Repository: lutris/lutris

Issue:
Ubisoft Connect game list not loading
### Bug description

Having installed Ubisoft Connect through Lutris and logged in properly, the list of games will not load on the latest git master, though it loads fine on v0.5.10-beta1. Seems to be related to commit 4db540ccbd712c7a04d84c001ea3edfea5d09ceb.

### How to Reproduce

Steps to reproduce the behavior:
1. Go to 'Ubisoft Connect' under Sources. The game list is empty.
2. Click on the reload button.
3. See an error box simply saying 'ownedPlatformGroups'.

### Expected behavior

Load the Ubisoft Connect owned game list.

### Log output

```shell
INFO     2022-02-19 12:45:58,672 [startup.init_lutris:164]:Starting Lutris 0.5.10
WARNING  2022-02-19 12:45:58,699 [libretro.get_libretro_cores:24]:No folder at /home/argy/.local/share/lutris/runners/retroarch/
INFO     2022-02-19 12:45:58,730 [startup.check_driver:65]:Running AMD Mesa driver 21.3.6 on AMD Radeon RX 580 Series (POLARIS10, DRM 3.44.0, 5.16.10-arch1-1, LLVM 13.0.1) (0x67df)
INFO     2022-02-19 12:45:58,731 [startup.check_driver:77]:GPU: 1002:67DF 148C:2378 (amdgpu drivers)
INFO     2022-02-19 12:45:58,772 [startup.update_runtime:203]:Startup complete
DEBUG    2022-02-19 12:45:58,968 [lutriswindow.update_store:431]:Showing 0 games
DEBUG    2022-02-19 12:46:04,782 [base.wipe_game_cache:297]:Deleting ubisoft cache /home/argy/.cache/lutris/ubisoft/library/
DEBUG    2022-02-19 12:46:04,782 [base.wipe_game_cache:121]:Deleting games from service-games for ubisoft
DEBUG    2022-02-19 12:46:04,783 [client._do_request_safe:74]:rememberMeTicket expiration time: 1645285457
INFO     2022-02-19 12:46:04,783 [client._do_request:58]:No headers in kwargs, using session headers
INFO     2022-02-19 12:46:05,325 [client._do_request:66]:Response status: <Response [200]>
DEBUG    2022-02-19 12:46:05,325 [client._do_request_safe:74]:rememberMeTicket expiration time: 1645285457
INFO     2022-02-19 12:46:05,325 [client._do_request:58]:No headers in kwargs, using session headers
INFO     2022-02-19 12:46:05,509 [client._do_request:66]:Response status: <Response [200]>
DEBUG    2022-02-19 12:46:05,510 [lutriswindow.update_store:431]:Showing 0 games
ERROR    2022-02-19 12:46:05,510 [jobs.target:36]:Error while completing task <bound method BaseService.reload of <ubisoft.UbisoftConnectService object at 0x7f45fe6aed00 (lutris+services+ubisoft+UbisoftConnectService at 0x5615ef99ef60)>>: <class 'KeyError'> 'ownedPlatformGroups'
  File "/usr/lib/python3.10/site-packages/lutris/util/jobs.py", line 34, in target
    result = self.function(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/lutris/services/base.py", line 96, in reload
    self.load()
  File "/usr/lib/python3.10/site-packages/lutris/services/ubisoft.py", line 156, in load
    for platform_group in game["ownedPlatformGroups"]:
INFO     2022-02-19 12:47:57,367 [application.do_shutdown:678]:Shutting down Lutris
```


### System Information

```shell
[System]
OS:              Arch Linux rolling n/a
Arch:            x86_64
Kernel:          5.16.10-arch1-1
Desktop:         GNOME
Display Server:  wayland

[CPU]
Vendor:          AuthenticAMD
Model:           AMD Ryzen 5 2600X Six-Core Processor
Physical cores:  6
Logical cores:   12

[Memory]
RAM:             15.6 GB
Swap:            12.0 GB

[Graphics]
Vendor:          AMD
OpenGL Renderer: AMD Radeon RX 580 Series (POLARIS10, DRM 3.44.0, 5.16.10-arch1-1, LLVM 13.0.1)
OpenGL Version:  4.6 (Compatibility Profile) Mesa 21.3.6
OpenGL Core:     4.6 (Core Profile) Mesa 21.3.6
OpenGL ES:       OpenGL ES 3.2 Mesa 21.3.6
Vulkan:          Supported
```


### Media (optional)

_No response_

### Checklist:

- [X] I'm not asking for support with a game or the wine runner.
- [X] I have followed the above mentioned guides and have all the graphics and wine dependencies installed.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.


Discussion:
Experiencing the same issue on my end.
Starting the runner works, but it fails while trying to reload games.

Resolving patch:
diff --git a/lutris/services/ubisoft.py b/lutris/services/ubisoft.py
--- a/lutris/services/ubisoft.py
+++ b/lutris/services/ubisoft.py
@@ -152,13 +152,14 @@ def load(self):
         games = response['data']['viewer']['ownedGames'].get('nodes', [])
         ubi_games = []
         for game in games:
-            is_pc = False
-            for platform_group in game["ownedPlatformGroups"]:
-                for platform in platform_group:
-                    if platform["type"] == "PC":
-                        is_pc = True
-            if not is_pc:
-                continue
+            if "ownedPlatformGroups" in game:
+                is_pc = False
+                for platform_group in game["ownedPlatformGroups"]:
+                    for platform in platform_group:
+                        if platform["type"] == "PC":
+                            is_pc = True
+                if not is_pc:
+                    continue
             ubi_game = UbisoftGame.new_from_api(game)
             ubi_game.save()
             ubi_games.append(ubi_game)


Test patch: