nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: beeware/briefcase
Pull request #876 (2022-09-27 04:11:50)

Fixed handling of missing model
added a try block to catch keyError when an android device has no model.
[Fixes issue #820](https://github.com/beeware/briefcase/issues/820#issue-1335035232)

## PR Checklist:
- [ ] All new features have been tested
- [ ] All new features have been documented
- [x] I have read the **CONTRIBUTING.md** file
- [x] I will abide by the code of conduct



Patch:
diff --git a/changes/820.bugfix.rst b/changes/820.bugfix.rst
new file mode 100644
index 00000000..b4eaddbc
--- /dev/null
+++ b/changes/820.bugfix.rst
@@ -0,0 +1,1 @@
+Android emulators that don't provide a model identifier can now be used to launch apps.
diff --git a/src/briefcase/integrations/android_sdk.py b/src/briefcase/integrations/android_sdk.py
index 15a8f85c..500754cd 100644
--- a/src/briefcase/integrations/android_sdk.py
+++ b/src/briefcase/integrations/android_sdk.py
@@ -640,7 +640,10 @@ connection.
                         details[key] = value
 
                     if parts[1] == "device":
-                        name = details["model"].replace("_", " ")
+                        try:
+                            name = details["model"].replace("_", " ")
+                        except KeyError:
+                            name = "Unknown device (no model name)"
                         authorized = True
                     elif parts[1] == "offline":
                         name = "Unknown device (offline)"


Test patch:
diff --git a/tests/integrations/android_sdk/AndroidSDK/devices/no_model.out b/tests/integrations/android_sdk/AndroidSDK/devices/no_model.out
new file mode 100644
index 00000000..b746a4df
--- /dev/null
+++ b/tests/integrations/android_sdk/AndroidSDK/devices/no_model.out
@@ -0,0 +1,2 @@
+List of devices attached
+emulator-5554          device product:sdk_phone_x86 device:generic_x86 transport_id:4
diff --git a/tests/integrations/android_sdk/AndroidSDK/test_devices.py b/tests/integrations/android_sdk/AndroidSDK/test_devices.py
index a1e78576..b0b1a285 100644
--- a/tests/integrations/android_sdk/AndroidSDK/test_devices.py
+++ b/tests/integrations/android_sdk/AndroidSDK/test_devices.py
@@ -21,6 +21,15 @@ def test_no_devices(mock_tools, android_sdk):
     assert android_sdk.devices() == {}
 
 
+def test_no_model(mock_tools, android_sdk):
+    """If there is no model, return Unknown device (no model name)"""
+    mock_tools.subprocess.check_output.return_value = devices_result("no_model")
+
+    assert android_sdk.devices() == {
+        "emulator-5554": {"name": "Unknown device (no model name)", "authorized": True}
+    }
+
+
 def test_one_emulator(mock_tools, android_sdk):
     """If there is a single emulator, it is returned."""
     mock_tools.subprocess.check_output.return_value = devices_result("one_emulator")