diff --git a/conans/search/search.py b/conans/search/search.py index 01e09bbe1ff..0cd26b46583 100644 --- a/conans/search/search.py +++ b/conans/search/search.py @@ -55,14 +55,14 @@ def compatible_prop(setting_value, _prop_value): return (_prop_value == setting_value) or (_prop_value == "None" and setting_value is None) # TODO: Necessary to generalize this query evaluation to include all possible fields - info_settings = binary_info.get("settings") - info_options = binary_info.get("options") + info_settings = binary_info.get("settings", {}) + info_options = binary_info.get("options", {}) if not prop_name.startswith("options."): - return compatible_prop(info_settings.get(prop_name, None), prop_value) + return compatible_prop(info_settings.get(prop_name), prop_value) else: prop_name = prop_name[len("options."):] - return compatible_prop(info_options.get(prop_name, None), prop_value) + return compatible_prop(info_options.get(prop_name), prop_value) def search_recipes(cache, pattern=None, ignorecase=True): diff --git a/conans/test/integration/command_v2/list_test.py b/conans/test/integration/command_v2/list_test.py index 87f5581a63c..6bd19fb6c9f 100644 --- a/conans/test/integration/command_v2/list_test.py +++ b/conans/test/integration/command_v2/list_test.py @@ -10,7 +10,7 @@ from conans.errors import ConanException, ConanConnectionError from conans.test.assets.genconanfile import GenConanfile -from conans.test.utils.tools import TestClient, TestServer +from conans.test.utils.tools import TestClient, TestServer, NO_SETTINGS_PACKAGE_ID from conans.util.env import environment_update from conans.util.files import load, save @@ -615,6 +615,24 @@ def test_list_query_options(): assert "myoption: 3" not in c.out +def test_list_empty_settings(): + """ + If settings are empty, do not crash + """ + c = TestClient(default_server_user=True) + c.save({"conanfile.py": GenConanfile("pkg", "1.0")}) + c.run("create .") + + c.run("list pkg/1.0:* -p os=Windows -f=json") + revisions = json.loads(c.stdout)["Local Cache"]["pkg/1.0"]["revisions"] + pkgs = revisions["a69a86bbd19ae2ef7eedc64ae645c531"]["packages"] + assert pkgs == {} + c.run("list pkg/1.0:* -p os=None -f=json") + revisions = json.loads(c.stdout)["Local Cache"]["pkg/1.0"]["revisions"] + pkgs = revisions["a69a86bbd19ae2ef7eedc64ae645c531"]["packages"] + assert pkgs == {NO_SETTINGS_PACKAGE_ID: {"info": {}}} + + class TestListNoUserChannel: def test_no_user_channel(self): c = TestClient(default_server_user=True)