From 1badb89df27d3ea599babe40476bf317b0b75d22 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Fri, 27 Mar 2020 14:10:09 +0000 Subject: [PATCH] nix_expr: Make list ordering deterministic --- nixops/nix_expr.py | 8 +++++++- tests/unit/test_nix_expr.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nixops/nix_expr.py b/nixops/nix_expr.py index c1bbc5296..ab53086b7 100644 --- a/nixops/nix_expr.py +++ b/nixops/nix_expr.py @@ -333,7 +333,13 @@ def _merge(e1, e2): if isinstance(e1, dict) and isinstance(e2, dict): return _merge_dicts(e1, e2) elif isinstance(e1, list) and isinstance(e2, list): - return list(set(e1).union(e2)) + l = [] + seen = set() + for x in e1 + e2: + if x not in seen: + seen.add(x) + l.append(x) + return l else: err = "unable to merge {0} with {1}".format(type(e1), type(e2)) raise ValueError(err) diff --git a/tests/unit/test_nix_expr.py b/tests/unit/test_nix_expr.py index f7a54fa93..64b9b8e6b 100644 --- a/tests/unit/test_nix_expr.py +++ b/tests/unit/test_nix_expr.py @@ -324,7 +324,7 @@ def assert_merge(self, sources, expect): def test_merge_list(self): self.assert_merge( [[1, 2, 3], [4, 5, 6], [7, 6, 5], ["abc", "def"], ["ghi", "abc"],], - [1, 2, 3, 4, 5, 6, 7, "ghi", "def", "abc"], + [1, 2, 3, 4, 5, 6, 7, "abc", "def", "ghi"], ) def test_merge_dict(self):