Repository: lutris/lutris

Issue:
TypeError: can only concatenate str (not "float") to str (self.playtime)
### Bug description

My distro supplies lutris 0.5.8.4.  I noticed that sometime in the recent past that games no longer track
playtime.  I haven't really troubled with it until now.  I found that by running lutris in a terminal, I can see
an error related to playtime:

```
2022-05-17 19:49:36,856: Game still running (state: running)
2022-05-17 19:49:36,857: Stopping The Lord of the Rings Online™ (wine)
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/lutris/game.py", line 535, in beat
    self.on_game_quit()
  File "/usr/lib/python3.8/site-packages/lutris/game.py", line 565, in on_game_quit
    self.stop()
  File "/usr/lib/python3.8/site-packages/lutris/game.py", line 553, in stop
    self.stop_game()
  File "/usr/lib/python3.8/site-packages/lutris/game.py", line 514, in stop_game
    self.playtime += self.timer.duration / 3600
TypeError: can only concatenate str (not "float") to str
2022-05-17 19:55:22,251: Shutting down Lutris
```

I see that there have been a number of playtime related issues in the past, but looking through the change log, I see no play-time relevant entries since 0.5.8.4.

Nevertheless, I tried downloading the latest release tarball and running lutris from it.  (Fortunately I had backed up pga.db beforehand while checking it.)  In any event, Lutris 0.5.10.1 does the same thing, albeit with different line numbers in game.py.

```
2022-05-17 19:56:57,929: Game still running (state: running)
2022-05-17 19:56:57,929: Stopping The Lord of the Rings Online™ (wine)
Traceback (most recent call last):
  File "/home/devel/lutris/lutris-0.5.10.1/lutris/game.py", line 665, in beat
    self.on_game_quit()
  File "/home/devel/lutris/lutris-0.5.10.1/lutris/game.py", line 691, in on_game_quit
    self.stop()
  File "/home/devel/lutris/lutris-0.5.10.1/lutris/game.py", line 679, in stop
    self.stop_game()
  File "/home/devel/lutris/lutris-0.5.10.1/lutris/game.py", line 639, in stop_game
    self.playtime += self.timer.duration / 3600
TypeError: can only concatenate str (not "float") to str
```

Heh, now my system lutris is borken because the schema pga.db updated.  Where's that backup... :-)

### How to Reproduce

Steps to reproduce the behavior:
1. Launch Lutris in a terminal.
2. Start a game
3. Stop the game
4. See the error in the terminal.


### Expected behavior

I do expect the Lutris GUI to not say "Never Played" when I have played many hours.

### Log output

```shell
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  151 (GLX)
  Minor opcode of failed request:  24 (X_GLXCreateNewContext)
  Value in failed request:  0x0
  Serial number of failed request:  110
  Current serial number in output stream:  111
2022-05-17 20:05:50,649: ['glxinfo', '-B'] command failed: Command '['glxinfo', '-B']' returned non-zero exit status 1.
2022-05-17 20:05:50,649: No available glxinfo output
2022-05-17 20:05:50,649: Invalid glxinfo received

(lutris:99151): Gtk-WARNING **: 20:05:51.167: Theme parsing error: gtk.css:2:33: Failed to import: Error opening file /home/krb/.config/gtk-3.0/window_decorations.css: No such file or directory
INFO     2022-05-17 20:05:51,196 [startup.init_lutris:173]:Starting Lutris 0.5.10.1
WARNING  2022-05-17 20:05:51,265 [libretro.get_libretro_cores:24]:No folder at /home/krb/.local/share/lutris/runners/retroarch/
DEBUG    2022-05-17 20:05:51,283 [xrandr._get_vidmodes:15]:Retrieving video modes from XrandR
INFO     2022-05-17 20:05:51,365 [startup.check_driver:57]:Using NVIDIA drivers 470.94 for x86_64
INFO     2022-05-17 20:05:51,365 [startup.check_driver:61]:GPU: NVIDIA GeForce GTX 750 Ti
INFO     2022-05-17 20:05:51,365 [startup.check_driver:77]:GPU: 10DE:1380 1043:84BB (nvidia drivers)
INFO     2022-05-17 20:05:51,480 [startup.update_runtime:213]:Startup complete
DEBUG    2022-05-17 20:05:51,672 [lutriswindow.update_store:437]:Showing 13 games
DEBUG    2022-05-17 20:06:07,041 [xrandr._get_vidmodes:15]:Retrieving video modes from XrandR
DEBUG    2022-05-17 20:06:07,079 [command.start:141]:DISABLE_LAYER_AMD_SWITCHABLE_GRAPHICS_1="1"
DEBUG    2022-05-17 20:06:07,079 [command.start:141]:__GL_SHADER_DISK_CACHE="1"
DEBUG    2022-05-17 20:06:07,079 [command.start:141]:__GL_SHADER_DISK_CACHE_PATH="/home/apps/Lutris/LordOfTheRingsOnline"
DEBUG    2022-05-17 20:06:07,079 [command.start:141]:LD_LIBRARY_PATH="/home/krb/.local/share/lutris/runners/wine/lutris-fshack-7.1-x86_64/lib:/home/krb/.local/share/lutris/runners/wine/lutris-fshack-7.1-x86_64/lib64:/lib64:/lib:/usr/lib64/R/lib:/lib/sse2:/usr/lib:/usr/lib64:/home/krb/.local/share/lutris/runtime/Ubuntu-18.04-i686:/home/krb/.local/share/lutris/runtime/steam/i386/lib/i386-linux-gnu:/home/krb/.local/share/lutris/runtime/steam/i386/lib:/home/krb/.local/share/lutris/runtime/steam/i386/usr/lib/i386-linux-gnu:/home/krb/.local/share/lutris/runtime/steam/i386/usr/lib:/home/krb/.local/share/lutris/runtime/Ubuntu-18.04-x86_64:/home/krb/.local/share/lutris/runtime/steam/amd64/lib/x86_64-linux-gnu:/home/krb/.local/share/lutris/runtime/steam/amd64/lib:/home/krb/.local/share/lutris/runtime/steam/amd64/usr/lib/x86_64-linux-gnu:/home/krb/.local/share/lutris/runtime/steam/amd64/usr/lib:$\{LD_LIBRARY_PATH\}:/usr/local/lib"
DEBUG    2022-05-17 20:06:07,079 [command.start:141]:WINEDEBUG="-all"
DEBUG    2022-05-17 20:06:07,079 [command.start:141]:DXVK_LOG_LEVEL="none"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:WINEARCH="win64"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:WINE="/home/krb/.local/share/lutris/runners/wine/lutris-fshack-7.1-x86_64/bin/wine"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:WINE_MONO_CACHE_DIR="/home/krb/.local/share/lutris/runners/wine/lutris-fshack-7.1-x86_64/mono"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:WINE_GECKO_CACHE_DIR="/home/krb/.local/share/lutris/runners/wine/lutris-fshack-7.1-x86_64/gecko"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:GST_PLUGIN_SYSTEM_PATH_1_0="/home/krb/.local/share/lutris/runners/wine/lutris-fshack-7.1-x86_64/lib64/gstreamer-1.0/:/home/krb/.local/share/lutris/runners/wine/lutris-fshack-7.1-x86_64/lib/gstreamer-1.0/"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:WINEPREFIX="/home/apps/Lutris/LordOfTheRingsOnline"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:WINEESYNC="1"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:WINEFSYNC="1"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:WINE_FULLSCREEN_FSR="1"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:DXVK_NVAPIHACK="0"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:DXVK_ENABLE_NVAPI="1"
DEBUG    2022-05-17 20:06:07,080 [command.start:141]:PROTON_BATTLEYE_RUNTIME="/home/krb/.local/share/lutris/runtime/battleye_runtime"
DEBUG    2022-05-17 20:06:07,081 [command.start:141]:PROTON_EAC_RUNTIME="/home/krb/.local/share/lutris/runtime/eac_runtime"
DEBUG    2022-05-17 20:06:07,081 [command.start:141]:WINEDLLOVERRIDES="d3d10core,d3d11,d3d12,d3d9,d3dcompiler_33,d3dcompiler_34,d3dcompiler_35,d3dcompiler_36,d3dcompiler_37,d3dcompiler_38,d3dcompiler_39,d3dcompiler_40,d3dcompiler_41,d3dcompiler_42,d3dcompiler_43,d3dcompiler_46,d3dcompiler_47,d3dx10,d3dx10_33,d3dx10_34,d3dx10_35,d3dx10_36,d3dx10_37,d3dx10_38,d3dx10_39,d3dx10_40,d3dx10_41,d3dx10_42,d3dx10_43,d3dx11_42,d3dx11_43,d3dx9_24,d3dx9_25,d3dx9_26,d3dx9_27,d3dx9_28,d3dx9_29,d3dx9_30,d3dx9_31,d3dx9_32,d3dx9_33,d3dx9_34,d3dx9_35,d3dx9_36,d3dx9_37,d3dx9_38,d3dx9_39,d3dx9_40,d3dx9_41,d3dx9_42,d3dx9_43,dxgi,nvapi,nvapi64,nvml=n;winemenubuilder="
DEBUG    2022-05-17 20:06:07,081 [command.start:141]:WINE_LARGE_ADDRESS_AWARE="1"
DEBUG    2022-05-17 20:06:07,081 [command.start:141]:game_name="The Lord of the Rings Online™"
DEBUG    2022-05-17 20:06:07,081 [command.start:141]:PYTHONPATH="/home/devel/lutris/lutris-0.5.10.1:/home/devel/lutris/lutris-0.5.10.1/bin:/usr/lib64/python38.zip:/usr/lib64/python3.8:/usr/lib64/python3.8/lib-dynload:/usr/lib64/python3.8/site-packages:/usr/lib/python3.8/site-packages"
DEBUG    2022-05-17 20:06:07,081 [command.start:141]:LUTRIS_GAME_UUID="62671d20-d875-48b4-b142-d9fd431c5078"
Started initial process 99177 from /home/krb/.local/share/lutris/runners/wine/lutris-fshack-7.1-x86_64/bin/wine /home/apps/Lutris/LordOfTheRingsOnline/drive_c/Program Files (x86)/StandingStoneGames/The Lord of the Rings Online/LotroLauncher.exe
Start monitoring process.
esync: up and running.
Monitored process exited.
Initial process has exited (return code: 0)
Exit with return code 0
DEBUG    2022-05-17 20:06:24,865 [command.on_stop:195]:Process 99175 has terminated with code 0
DEBUG    2022-05-17 20:06:29,140 [game.beat:664]:Game thread stopped
WARNING  2022-05-17 20:06:29,140 [game.on_game_quit:690]:Game still running (state: running)
INFO     2022-05-17 20:06:29,140 [game.stop:675]:Stopping The Lord of the Rings Online™ (wine)
DEBUG    2022-05-17 20:06:29,141 [game.stop_game:628]:The Lord of the Rings Online™ (wine) has run for 22 seconds
Traceback (most recent call last):
  File "/home/devel/lutris/lutris-0.5.10.1/lutris/game.py", line 665, in beat
    self.on_game_quit()
  File "/home/devel/lutris/lutris-0.5.10.1/lutris/game.py", line 691, in on_game_quit
    self.stop()
  File "/home/devel/lutris/lutris-0.5.10.1/lutris/game.py", line 679, in stop
    self.stop_game()
  File "/home/devel/lutris/lutris-0.5.10.1/lutris/game.py", line 639, in stop_game
    self.playtime += self.timer.duration / 3600
TypeError: can only concatenate str (not "float") to str
INFO     2022-05-17 20:06:46,720 [application.do_shutdown:885]:Shutting down Lutris
```


### System Information

```shell
[System]
OS:              Mageia 8 mga8
Arch:            x86_64
Kernel:          5.15.32-desktop-1.mga8
Desktop:         KDE
Display Server:  x11

[CPU]
Vendor:          AuthenticAMD
Model:           AMD FX(tm)-6300 Six-Core Processor
Physical cores:  3
Logical cores:   6

[Memory]
RAM:             15.5 GB
Swap:            3.9 GB

[Graphics]
Vendor:          Unable to obtain glxinfo
Vulkan:          Supported
```


### Media (optional)


![Screenshot_20220517_201001](https://user-images.githubusercontent.com/37119764/168936787-17545198-0747-4fc6-b1bb-ca2ec8989a08.png)


### 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:
Uh, ok, not good. Icons for games are all blank now.  I guess was necessary to backup the whole ~/.local/share/lutris before trying the new version, and not just the pga.db!  Wow, now not really amused by trying out the new version.  I guess running the new version wiped stuff including Lutris account information.  After renewing the Lutris login information, connecting, and viewing my library there, the icons from the Lutris account were restored -- but no luck on the stuff I installed that isn't in the Lutris database.
> My distro supplies lutris 0.5.8.4.

We don't support this version anymore, shout at your distro maintainers and tell them to upgrade.

> I guess was necessary to backup the whole ~/.local/share/lutris before trying the new version

It is not necessary to backup anything when updating lutris. We don't delete anything.
I went to the trouble of actually testing and testing the latest version to be most helpful and to avoid reasonable possibility of reporting a bug that might have already been fixed to extent of breaking the configuration for the distro version.  Of course the old version isn't supported, and, I don't want to run a distro that runs bleeding edge versions exactly on every individual project's release schedule if one even exists (so I do not need to shout at them), and, that's why I tested the latest release on github as is clearly shown in the second two captures.

I guess I triggered something... so yeah I should have left the part about having to fix the icon thing out of the report, but, yes, it did effectively blank all the icons, or meta-data that describes what icons to show.  I can imagine that it didn't delete data so much as change the format so the old version couldn't read it anymore. I suppose now after looking deeper, in one of the files under .config.  Nevertheless, that is not the issue of main concern. I fixed that myself.

Here's wishing you a pleasant day, week, month, etc.
We have moved game media from ~/.local/share/lutris to ~/.cache/lutris so if you run 0.5.10 then roll back to a previous version, the icons won't be accessible indeed.

I believe the following fixes the issues both in my old distro version and in 0.5.10.1:

```
+++ lutris-0.5.10.1/lutris/game.py      2022-05-19 11:14:07.692394659 -0500
@@ -636,7 +636,7 @@
             os.unlink(self.now_playing_path)
         if not self.timer.finished:
             self.timer.end()
-            self.playtime += self.timer.duration / 3600
+            self.playtime = str(float(self.playtime) + self.timer.duration / 3600)

     def prelaunch_beat(self):
         """Watch the prelaunch command"""
```

This makes it so both **Last Played** and **Time Played** update when a game stops.
This is the commit where the code last changed:

https://github.com/lutris/lutris/commit/68d7fade47a21968f947c5403f5aa6bc46942b12

but the bug seems to have originated earlier than that.

Resolving patch:
diff --git a/lutris/game.py b/lutris/game.py
--- a/lutris/game.py
+++ b/lutris/game.py
@@ -93,7 +93,7 @@ def __init__(self, game_id=None):
             self.custom_images.add("coverart_big")
         self.service = game_data.get("service")
         self.appid = game_data.get("service_id")
-        self.playtime = game_data.get("playtime") or 0.0
+        self.playtime = float(game_data.get("playtime") or 0.0)
 
         if self.game_config_id:
             self.load_config()


Test patch: