internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: lutris/lutris

Issue:
sqlite3.IntegrityError: UNIQUE constraint failed: games.id
Trying to change a game from one runner to another and it "fails" if you press apply it jus sits there doing nothing,  I get this on the terminal 

  ```
File "~/src/lutris/lutris/gui/config_dialogs.py", line 376, in on_save
    self.game.save()
  File "~/src/lutris/lutris/game.py", line 173, in save
    playtime=self.playtime,
  File "~/src/lutris/lutris/pga.py", line 262, in add_or_update
    return add_game(**params)
  File "~/src/lutris/lutris/pga.py", line 225, in add_game
    return sql.db_insert(PGA_DB, "games", game_data)
  File "~/src/lutris/lutris/util/sql.py", line 54, in db_insert
    field_values
  File "~/src/lutris/lutris/util/sql.py", line 30, in cursor_execute
    return cursor.execute(query, params)
sqlite3.IntegrityError: UNIQUE constraint failed: games.id

```


Discussion:

Resolving patch:
diff --git a/lutris/gui/config_dialogs.py b/lutris/gui/config_dialogs.py
--- a/lutris/gui/config_dialogs.py
+++ b/lutris/gui/config_dialogs.py
@@ -362,12 +362,16 @@ def on_save(self, _button, callback=None):
         if self.lutris_config.game_config_id == TEMP_CONFIG:
             self.lutris_config.game_config_id = self.get_config_id()
 
+        # Delete the old copy of the game if the runner changes
         runner_class = runners.import_runner(self.runner_name)
         runner = runner_class(self.lutris_config)
+        if self.game.platform != runner.get_platform():
+            self.game.remove()
+        self.game.runner_name = self.runner_name
+
         self.game.name = name
         self.game.slug = self.slug
         self.game.year = year
-        self.game.runner_name = self.runner_name
         self.game.config = self.lutris_config
         self.game.directory = runner.game_path
         self.game.is_installed = True


Test patch:
Repository: lutris/lutris

Issue:
Do not show message about missing gamemode in terminal output
This may confuse users and make them believe it's some kind of essential library.
```
2019-01-08 05:39:36,869: i386 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 05:39:36,869: x86_64 libgamemodeauto.so missing (needed by gamemode)
```


Discussion:
I am going to re-open this because I get even more of them now:
```./bin/lutris
2019-01-08 13:18:09,256: Running Lutris 0.5.0-beta
2019-01-08 13:18:09,262: Using NVIDIA drivers 415.25 for x86_64
2019-01-08 13:18:09,262: GPU: GeForce GTX 1070
2019-01-08 13:18:09,262: GPU: 10DE:1B81 1458:3772 using nvidia driver
2019-01-08 13:18:09,263: i386 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 13:18:09,263: x86_64 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 13:18:09,263: i386 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 13:18:09,263: x86_64 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 13:18:09,263: i386 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 13:18:09,263: x86_64 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 13:18:09,263: i386 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 13:18:09,263: x86_64 libgamemodeauto.so missing (needed by gamemode)
2019-01-08 13:18:09,281: Vulkan is supported
2019-01-08 13:18:09,422: Connected to lutris.net as citrusalex
```
it's not related
Uhhh, can you explain? The issue is about gamemode messages, and they are still present.

Resolving patch:
diff --git a/lutris/util/system.py b/lutris/util/system.py
--- a/lutris/util/system.py
+++ b/lutris/util/system.py
@@ -170,7 +170,7 @@ def critical_requirements(self):
 
     def get_requirements(self, include_optional=True):
         """Return used system requirements"""
-        _requirements = self.required_components
+        _requirements = self.required_components.copy()
         if include_optional:
             _requirements += self.optional_components
             if drivers.is_amd():


Test patch:
Repository: lutris/lutris

Issue:
DXVK overrides get shown in DLL Overrides section while the game is running, remain if config is changed during that
How to reproduce:
1. Enable DXVK, save.
2. Launch the game.
3. Open Configuration while the game is still running
4. Change any option (for example, DXVK), save.
5. Stop the game.

Observed behavior: While the game is still running, DXVK overrides (d3d11, dxgi, etc.) are shown in `DLL Overrides` section. If you change configuration during that, for example, disable DXVK, these overrides will actually be saved into game configuration despite DXVK being disabled, leading to issues with WineD3D afterwards.
Expected behavior: none of what is described above.

_Note: if you actually don't change or open configuration while the game is still running, the overrides will not be shown in configuration after stopping the game._

![peek 2019-01-13 18-58](https://user-images.githubusercontent.com/10602045/51087597-692a6580-1766-11e9-9f27-186d03ec02e4.gif)



Discussion:

Resolving patch:
diff --git a/lutris/runners/wine.py b/lutris/runners/wine.py
--- a/lutris/runners/wine.py
+++ b/lutris/runners/wine.py
@@ -680,10 +680,17 @@ def prelaunch(self):
 
     def get_dll_overrides(self):
         """Return the DLLs overriden at runtime"""
-        overrides = self.runner_config.get("overrides") or {}
-        if not isinstance(overrides, dict):
-            logger.warning("DLL overrides is not a mapping: %s", overrides)
+        try:
+            overrides = self.runner_config['overrides']
+        except KeyError:
             overrides = {}
+        else:
+            if not isinstance(overrides, dict):
+                logger.warning("DLL overrides is not a mapping: %s", overrides)
+                overrides = {}
+            else:
+                overrides = overrides.copy()
+
         overrides.update(self.dll_overrides)
         return overrides
 


Test patch:
Repository: lutris/lutris

Issue:
[master] Can't open winecfg
**Steps to reproduce:** Right click a wine game -> Wine Configuration
**Expected behaviour:** Winecfg opens without any tracebacks
**Observed behaviour:** Winecfg does not open. Terminal prints this:
```
DEBUG    2019-01-15 15:25:39,885 [wine.winecfg:365]:winecfg: /home/username/.local/share/lutris/runners/wine/tkg-3.21-x86_64/bin/winecfg
Traceback (most recent call last):
  File "/home/username/Desktop/git-projects/lutris/real/lutris/runners/wine.py", line 589, in run_winecfg
    config=self,
  File "/home/username/Desktop/git-projects/lutris/real/lutris/runners/commands/wine.py", line 374, in winecfg
    include_processes=["winecfg.exe"],
  File "/home/username/Desktop/git-projects/lutris/real/lutris/runners/commands/wine.py", line 247, in wineexec
    include_processes = shlex.split(include_processes or "")
  File "/usr/lib/python3.7/shlex.py", line 305, in split
    return list(lex)
  File "/usr/lib/python3.7/shlex.py", line 295, in __next__
    token = self.get_token()
  File "/usr/lib/python3.7/shlex.py", line 105, in get_token
    raw = self.read_token()
  File "/usr/lib/python3.7/shlex.py", line 136, in read_token
    nextchar = self.instream.read(1)
AttributeError: 'list' object has no attribute 'read'
```


Discussion:

Resolving patch:
diff --git a/lutris/runners/commands/wine.py b/lutris/runners/commands/wine.py
--- a/lutris/runners/commands/wine.py
+++ b/lutris/runners/commands/wine.py
@@ -244,8 +244,10 @@ def wineexec(
         MonitoredCommand instance otherwise.
     """
     executable = str(executable) if executable else ""
-    include_processes = shlex.split(include_processes or "")
-    exclude_processes = shlex.split(exclude_processes or "")
+    if isinstance(include_processes, str):
+        include_processes = shlex.split(include_processes)
+    if isinstance(exclude_processes, str):
+        exclude_processes = shlex.split(exclude_processes)
     if not wine_path:
         wine = import_runner("wine")
         wine_path = wine().get_executable()


Test patch:
Repository: lutris/lutris

Issue:
Saving game settings causes a traceback
```
Traceback (most recent call last):
  File "/mnt/extrastorage/lutris/lutris/gui/lutriswindow.py", line 666, in on_game_updated
    self.view.set_selected_game(game.id)
  File "/mnt/extrastorage/lutris/lutris/gui/views/list.py", line 123, in set_selected_game
    row = self.get_row_by_id(game_id, filtered=True)
AttributeError: 'GameListView' object has no attribute 'get_row_by_id'
```

`GameListView` does not seem to provide that method. 

After the traceback occurs, Lutris will try to update the default wine prefix (`~/.wine`) rather than the correct one and must be restarted.


Discussion:

Resolving patch:
diff --git a/lutris/gui/views/list.py b/lutris/gui/views/list.py
--- a/lutris/gui/views/list.py
+++ b/lutris/gui/views/list.py
@@ -120,7 +120,7 @@ def select(self):
         self.set_cursor(self.current_path[0])
 
     def set_selected_game(self, game_id):
-        row = self.get_row_by_id(game_id, filtered=True)
+        row = self.game_store.get_row_by_id(game_id, filtered=True)
         if row:
             self.set_cursor(row.path)
 


Test patch:
Repository: lutris/lutris

Issue:
Do not set DRI_PRIME to 0 if hybrid graphics are not detected
Currently, Lutris will set DRI_PRIME to 0 if it can't detect dedicated GPU, which is pretty bad as a bug in the detection of hybrid graphics (like https://github.com/lutris/lutris/issues/1732) will make it impossible to set DRI_PRIME envar to 1 manually through envar menu (Lutris will override manually set value and set it to 0 anyway) and workaround such bug in Lutris, thus making it impossible to use dedicated GPU for games installed through Lutris.
What Lutris should do instead is just not set DRI_PRIME to anything if it can't detect hybrid graphics.


Discussion:
Agree. Do you have any example of bug in detection of hybrid graphics? (bug #1732 is already fixed).
Well, not at the moment, but in case a similar bug appears, it would be nice if we had a workaround option available.
I confirm as another person that there is such an error. In earlier versions, `DRI_PRIME` worked correctly. I've tried to use Lutris 0.5 lately and the game does not see/work the variable `DRI_PRIME=1` at all.

Resolving patch:
diff --git a/lutris/runners/runner.py b/lutris/runners/runner.py
--- a/lutris/runners/runner.py
+++ b/lutris/runners/runner.py
@@ -141,7 +141,8 @@ def get_env(self, os_env=False):
         system_env = self.system_config.get("env") or {}
         env.update(system_env)
 
-        env["DRI_PRIME"] = "1" if self.system_config.get("dri_prime") else "0"
+        if self.system_config.get("dri_prime"):
+            env["DRI_PRIME"] = "1"
 
         runtime_ld_library_path = None
 
diff --git a/lutris/sysoptions.py b/lutris/sysoptions.py
--- a/lutris/sysoptions.py
+++ b/lutris/sysoptions.py
@@ -151,7 +151,7 @@ def get_optirun_choices():
     {
         "option": "dri_prime",
         "type": "bool",
-        "default": False,
+        "default": display.USE_DRI_PRIME,
         "condition": display.USE_DRI_PRIME,
         "label": "Use PRIME (hybrid graphics on laptops)",
         "advanced": True,


Test patch:
Repository: lutris/lutris

Issue:
get_children_pids_of_thread(): process.py:57:get_children_pids_of_thread:ProcessLookupError: [Errno 3] No such process: '/proc/25892/task/25892/children'
Here's another Fedora report.

https://bugzilla.redhat.com/show_bug.cgi?id=1686988

cmdline:        /usr/bin/python3 -s /usr/bin/lutris-wrapper 0 0 /home/u13881/.local/share/lutris/runtime/winetricks/winetricks --unattended
crash_function: get_children_pids_of_thread
exception_type: ProcessLookupError
executable:     /usr/bin/lutris-wrapper
interpreter:    python3-3.7.2-4.fc29.x86_64
kernel:         4.20.13-200.fc29.x86_64
runlevel:       N 5
type:           Python3
uid:            1000

Truncated backtrace:
process.py:57:get_children_pids_of_thread:ProcessLookupError: [Errno 3] No such process: '/proc/25892/task/25892/children'

Traceback (most recent call last):
  File "/usr/bin/lutris-wrapper", line 110, in <module>
    main()
  File "/usr/bin/lutris-wrapper", line 91, in main
    if not monitor.refresh_process_status():
  File "/usr/lib/python3.7/site-packages/lutris/util/monitor.py", line 98, in refresh_process_status
    for child in self.iter_children(Process(os.getpid())):
  File "/usr/lib/python3.7/site-packages/lutris/util/process.py", line 20, in __init__
    self.get_children()
  File "/usr/lib/python3.7/site-packages/lutris/util/process.py", line 67, in get_children
    self.children.append(Process(child_pid, parent=self))
  File "/usr/lib/python3.7/site-packages/lutris/util/process.py", line 20, in __init__
    self.get_children()
  File "/usr/lib/python3.7/site-packages/lutris/util/process.py", line 67, in get_children
    self.children.append(Process(child_pid, parent=self))
  File "/usr/lib/python3.7/site-packages/lutris/util/process.py", line 20, in __init__
    self.get_children()
  File "/usr/lib/python3.7/site-packages/lutris/util/process.py", line 66, in get_children
    for child_pid in self.get_children_pids_of_thread(tid):
  File "/usr/lib/python3.7/site-packages/lutris/util/process.py", line 57, in get_children_pids_of_thread
    with open(children_path) as children_file:
ProcessLookupError: [Errno 3] No such process: '/proc/25892/task/25892/children'

Local variables in innermost frame:
self: Process 25892
tid: '25892'
children_path: '/proc/25892/task/25892/children'


Discussion:
Hmm, looks like a race condition. The process seems to die in between learning of its existence and us trying to learn information about it. This should be pretty easy to fix.

Resolving patch:
diff --git a/lutris/util/process.py b/lutris/util/process.py
--- a/lutris/util/process.py
+++ b/lutris/util/process.py
@@ -56,7 +56,7 @@ def get_children_pids_of_thread(self, tid):
         try:
             with open(children_path) as children_file:
                 children_content = children_file.read()
-        except FileNotFoundError:
+        except (FileNotFoundError, ProcessLookupError):
             children_content = ""
         return children_content.strip().split()
 


Test patch:
Repository: lutris/lutris

Issue:
Higher resolution icons are still saved in 32x32 directory
Despite Lutris bumping its icon size to 128x128 (currently it's still 64x64 as bump to 128x128 hasn't been deployed yet), it still saves the icons into `icons/hicolor/32x32`.
It should probably not do that and save it in proper 128x128 location instead.


Discussion:

Resolving patch:
diff --git a/lutris/settings.py b/lutris/settings.py
--- a/lutris/settings.py
+++ b/lutris/settings.py
@@ -23,7 +23,7 @@
 TMP_PATH = os.path.join(CACHE_DIR, "tmp")
 BANNER_PATH = os.path.join(DATA_DIR, "banners")
 COVERART_PATH = os.path.join(DATA_DIR, "coverart")
-ICON_PATH = os.path.join(GLib.get_user_data_dir(), "icons", "hicolor", "32x32", "apps")
+ICON_PATH = os.path.join(GLib.get_user_data_dir(), "icons", "hicolor", "128x128", "apps")
 
 sio = SettingsIO(CONFIG_FILE)
 PGA_DB = sio.read_setting("pga_path") or os.path.join(DATA_DIR, "pga.db")


Test patch:
Repository: lutris/lutris

Issue:
Can't launch games on master with prefer system libraries enabled
```
DEBUG    2019-03-30 14:02:57,737 [application.launch:341]:Adding game EFMB (linux) (140618847460016) to running games
DEBUG    2019-03-30 14:02:57,742 [display._get_vidmodes:15]:Retrieving video modes from XrandR
DEBUG    2019-03-30 14:02:57,761 [game.configure_game:305]:Launching EFMB: {'command': ['/home/cxf/Downloads/EFMB_linux/EFMB/runner']}
DEBUG    2019-03-30 14:02:57,761 [game.configure_game:306]:Game info: {
  "command": [
    "/home/cxf/Downloads/EFMB_linux/EFMB/runner"
  ]
}
Traceback (most recent call last):
  File "/home/cxf/.lutris/lutris/game_actions.py", line 156, in on_game_run
    self.application.launch(self.game)
  File "/home/cxf/.lutris/lutris/gui/application.py", line 344, in launch
    game.play()
  File "/home/cxf/.lutris/lutris/game.py", line 277, in play
    self.configure_game(True)
  File "/home/cxf/.lutris/lutris/exceptions.py", line 26, in wrapper
    return function(*args, **kwargs)
  File "/home/cxf/.lutris/lutris/game.py", line 447, in configure_game
    game_env = gameplay_info.get("env") or self.runner.get_env()
  File "/home/cxf/.lutris/lutris/runners/runner.py", line 149, in get_env
    runtime_env = self.get_runtime_env()
  File "/home/cxf/.lutris/lutris/runners/runner.py", line 176, in get_runtime_env
    prefer_system_libs=self.system_config.get("prefer_system_libs", True)
  File "/home/cxf/.lutris/lutris/runtime.py", line 214, in get_env
    wine_path=wine_path
  File "/home/cxf/.lutris/lutris/runtime.py", line 291, in get_paths
    wine_path=wine_path
  File "/home/cxf/.lutris/lutris/runtime.py", line 279, in get_runtime_paths
    paths += get_system_paths()
  File "/home/cxf/.lutris/lutris/runtime.py", line 240, in get_system_paths
    paths.append(lib_paths[index])
IndexError: list index out of range
```

Git bisect:

```
4bd62c999808615a4840932af2685ddd695886c9 is the first bad commit
commit 4bd62c999808615a4840932af2685ddd695886c9
Author: aTosser <38044923+aTosser@users.noreply.github.com>
Date:   Sat Mar 30 06:25:41 2019 -0400

    Uses dynamic procedure for deducing library paths.
    
    Use ldconfig and parse results to locate all possible library paths on the system guided by the linker.

:040000 040000 e2e31e7c9a98cfe1c3e9360d33d6b860898769cd 57fae548dbcbb003d206fda2d9bc4458290622d5 M	lutris
```

@aTosser 


Discussion:
called it!
What distro is this on? Perhaps I can evaluate the problem in a VM.

Resolving patch:
diff --git a/lutris/runtime.py b/lutris/runtime.py
--- a/lutris/runtime.py
+++ b/lutris/runtime.py
@@ -236,8 +236,8 @@ def get_system_paths():
     # This prioritizes system libraries over
     # the Lutris and Steam runtimes.
     for lib_paths in LINUX_SYSTEM.iter_lib_folders():
-        for index, _arch in enumerate(LINUX_SYSTEM.runtime_architectures):
-            paths.append(lib_paths[index])
+        for path in lib_paths:
+            paths.append(path)
     return paths
 
 


Test patch:
Repository: lutris/lutris

Issue:
Wine cannot find the FreeType font library
Origin doesn't render when "Prefer system libraries" is enabled.

![Screenshot from 2019-04-01 18-02-29](https://user-images.githubusercontent.com/15083452/55368762-7d9a1680-54a8-11e9-8633-dbd25e25fd48.png)

[lutris-origin-log.txt](https://github.com/lutris/lutris/files/3031911/lutris-origin-log.txt)

@aTosser 


Discussion:

Resolving patch:
diff --git a/lutris/util/linux.py b/lutris/util/linux.py
--- a/lutris/util/linux.py
+++ b/lutris/util/linux.py
@@ -220,27 +220,26 @@ def get_fs_type_for_path(self, path):
                     return partition["fstype"]
 
     def get_lib_folders(self):
-        # Use ldconfig to locate the correct locations for system libs.
-        _paths = [[], []]
-        _candidates = (
-            subprocess.Popen([self.get("ldconfig"), '-p'],
-                             stdout=subprocess.PIPE,
-                             universal_newlines=True)
-        ).communicate()[0].split('\n')
-        for req in self.requirements:
-            for candidate in _candidates:
-                for lib in SYSTEM_COMPONENTS["LIBRARIES"][req]:
-                    if lib in candidate:
-                        if 'x86-64' in candidate:
-                            candidate = candidate.split(' => ')[1].split(lib)[0]
-                            if candidate not in _paths[1]:
-                                _paths[1].append(candidate)
-                        else:
-                            candidate = candidate.split(' => ')[1].split(lib)[0]
-                            if candidate not in _paths[0]:
-                                _paths[0].append(candidate)
+        # Use ldconfig to locate the correct locations for system libs. Sorting is done to preserve ordering for the distros that care.
+        _cand_dict = {}
+        for candidate in subprocess.run([self.get("ldconfig"), '-p'], stdout=subprocess.PIPE, universal_newlines=True).stdout.split('\n'):
+            if '=>' in candidate:
+                candidate = candidate.split(' => ')
+                if candidate[0] not in _cand_dict:
+                    _cand_dict.update({candidate[0]: [candidate[1].rsplit('/', 1)[0]]})
+                else:
+                    _cand_dict[candidate[0]].append(candidate[1].rsplit('/', 1)[0])
+        _paths = [[],[]]
+        for candidate, path in sorted(_cand_dict.items(), key = lambda cand: len(cand[1]), reverse = True):
+            if 'x86-64' in candidate:
+                if  path[0] not in _paths[1]:
+                    _paths[1].append(path[0])
+            elif 'libc' in candidate:
+                if path[0] not in _paths[0]:
+                    _paths[0].append(path[0])
         return _paths
 
+
     def get_glxinfo(self):
         """Return a GlxInfo instance if the gfxinfo tool is available"""
         if not self.get("glxinfo"):


Test patch:
Repository: lutris/lutris

Issue:
Lutris doesn't completely kill Wine processes in the prefix after cancellation of the installation
It's not uncommon for me to get "creating prefix" messages just after cancellation of the game installation and see active processes that were launched during installation process in System Monitor (which are what triggering prefix re-creation after Lutris deletes it).
And same happens if the installation is not cancelled (which might caused issues with WINEESYNC option).
Perhaps Lutris should use `wineserver -k9` for this.


Discussion:

Resolving patch:
diff --git a/lutris/gui/installerwindow.py b/lutris/gui/installerwindow.py
--- a/lutris/gui/installerwindow.py
+++ b/lutris/gui/installerwindow.py
@@ -24,6 +24,8 @@
 from lutris.util.log import logger
 from lutris.util.strings import add_url_tags, escape_gtk_label
 
+from subprocess import Popen
+from shutil import which
 
 class InstallerWindow(BaseApplicationWindow):
     """GUI for the install process."""
@@ -481,6 +483,8 @@ def cancel_installation(self, widget=None):
             }
         )
         if confirm_cancel_dialog.result != Gtk.ResponseType.YES:
+            ws_path = which('wineserver')
+            Popen([ws_path, '-k9'])
             return True
         if self.interpreter:
             self.interpreter.revert()


Test patch:
Repository: lutris/lutris

Issue:
Lutris defaults antialiasing to "0" and overrides any in-app options for all wined3d games
Because of this, all games are forced to disable smoothing and it can't be changed in-game, only in Lutris config. 
Caused by https://github.com/lutris/lutris/pull/1609 from @TRPB .


Discussion:

Resolving patch:
diff --git a/lutris/runners/wine.py b/lutris/runners/wine.py
--- a/lutris/runners/wine.py
+++ b/lutris/runners/wine.py
@@ -351,13 +351,14 @@ def dxvk_vulkan_callback(widget, option, config):
                 "label": "Anti-aliasing Sample Count",
                 "type": "choice",
                 "choices": [
-                    ("0", "0 (disabled)"),
+                    ("Auto", "auto"),
+                    ("0", "0"),
                     ("2", "2"),
                     ("4", "4"),
                     ("8", "8"),
                     ("16", "16")
                 ],
-                "default": "0",
+                "default": "auto",
                 "advanced": True,
                 "help": (
                     "Override swapchain sample count. It can be used to force enable multisampling "
@@ -682,7 +683,7 @@ def set_regedit_keys(self):
         for key, path in self.reg_keys.items():
             value = self.runner_config.get(key) or "auto"
             if not value or value == "auto" and key not in managed_keys.keys():
-                prefix_manager.clear_registry_key(path)
+                prefix_manager.clear_registry_subkeys(path, key)
             elif key in self.runner_config:
                 if key in managed_keys.keys():
                     # Do not pass fallback 'auto' value to managed keys


Test patch: