From ffbf75073a2016774fa1e9ae306ce1b503b58638 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 19 Apr 2024 15:34:16 -0700 Subject: [PATCH] osbuild-depsolve-dnf5: Handle null transactions and exclude-specs The JSON output by go will use 'null' for nil slices, so we need to use a [] when the field is missing, or when it is set to null. Previously this was handled by checking the value before iterating but when the code moved for the directory handling it was changed. This implements the same behavior in a slightly cleaner way. --- tools/osbuild-depsolve-dnf5 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/osbuild-depsolve-dnf5 b/tools/osbuild-depsolve-dnf5 index 1f060eeb..64afd199 100755 --- a/tools/osbuild-depsolve-dnf5 +++ b/tools/osbuild-depsolve-dnf5 @@ -101,9 +101,11 @@ class Solver(): # Gather up all the exclude packages from all the transactions exclude_pkgs = [] - transactions = arguments.get("transactions", []) + # Return an empty list when 'transactions' key is missing or when it is None + transactions = arguments.get("transactions") or [] for t in transactions: - exclude_pkgs.extend(t.get("exclude-specs", [])) + # Return an empty list when 'exclude-specs' key is missing or when it is None + exclude_pkgs.extend(t.get("exclude-specs") or []) if not exclude_pkgs: exclude_pkgs = [] @@ -358,7 +360,8 @@ class Solver(): def depsolve(self, arguments): """depsolve returns a list of the dependencies for the set of transactions """ - transactions = arguments.get("transactions", []) + # Return an empty list when 'transactions' key is missing or when it is None + transactions = arguments.get("transactions") or [] # collect repo IDs from the request so we know whether to translate gpg key paths request_repo_ids = set(repo["id"] for repo in arguments.get("repos", [])) root_dir = arguments.get("root_dir")