From ca2a60f60822ba8954eb813924a0894512414193 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:35:43 -0600 Subject: [PATCH] fix(deploy): validate() reports unhashable restart/class values by field instead of crashing (#6388) --- lib/default.nix | 21 +++++++++++++++++++++ pkgs/deploy/deploy.py | 8 ++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 1b174326c..d8f777dd3 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1215,6 +1215,14 @@ let dupFieldRegistry = pkgs.writeText "deploy-targets-dup-field.json" '' {"svc": {"ports": "notalist", "ports": []}} ''; + # Unhashable restart/class values (issue #6388): arrays/objects + # where validate() expects a string. validate() must report + # them by field, not crash with a TypeError, and one + # crashing-shape service must not suppress another service's + # ordinary field reports. + unhashableRegistry = pkgs.writeText "deploy-targets-unhashable.json" '' + {"bad": {"class": ["systemd"], "restart": ["always"]}, "other": {"class": {"x": 1}, "restart": "sometimes"}} + ''; in { packages.deploy = deployPkgs.deploy; @@ -1263,6 +1271,19 @@ let fi grep -q "duplicate key 'ports'" dup-field-err.txt test ! -s dup-field-out.txt + if ${deployPkgs.deploy}/bin/deploy list --registry ${unhashableRegistry} > unhash-out.txt 2> unhash-err.txt; then + echo "deploy list accepted a registry with unhashable restart/class values" >&2 + exit 1 + fi + grep -q "service 'bad': restart must be one of" unhash-err.txt + grep -q "service 'bad': class must be one of" unhash-err.txt + grep -q "service 'other': class must be one of" unhash-err.txt + grep -q "service 'other': restart must be one of" unhash-err.txt + if grep -q "Traceback" unhash-err.txt; then + echo "deploy list crashed with a traceback on unhashable values" >&2 + exit 1 + fi + test ! -s unhash-out.txt mkdir -p $out cp err.txt $out/errors.txt ''; diff --git a/pkgs/deploy/deploy.py b/pkgs/deploy/deploy.py index 6ab22aa40..b81ccfd2f 100644 --- a/pkgs/deploy/deploy.py +++ b/pkgs/deploy/deploy.py @@ -122,7 +122,9 @@ def validate(registry): errors.append(f"{where}: ports must be a list of integers in 1..65535") elif len(set(ports)) != len(ports): errors.append(f"{where}: ports must not repeat a port") - if "restart" in defn and defn["restart"] not in RESTART_POLICIES: + if "restart" in defn and not ( + isinstance(defn["restart"], str) and defn["restart"] in RESTART_POLICIES + ): errors.append( f"{where}: restart must be one of {', '.join(sorted(RESTART_POLICIES))}" ) @@ -141,7 +143,9 @@ def validate(registry): errors.append( f"{where}: targets must be a non-empty list of host/class names" ) - if "class" in defn and defn["class"] not in CLASSES: + if "class" in defn and not ( + isinstance(defn["class"], str) and defn["class"] in CLASSES + ): errors.append(f"{where}: class must be one of {', '.join(sorted(CLASSES))}") return errors