From 086ae04b9e01c06e9614e58b5b9e402a8f5298c2 Mon Sep 17 00:00:00 2001 From: Nicolas Barbey Date: Mon, 17 Oct 2016 15:02:48 +0200 Subject: [PATCH] Fix TypeError : unorderable types: str() < int() While merging list items into a set, strings and ints are compared which is not possible. We cast everything to strings to avoid the issue. The issue was seen with python 3.5 while overriding configuration files with heterogenous port types (int in one file, string in another). Signed-off-by: Nicolas Barbey --- compose/config/config.py | 2 ++ tests/unit/config/config_test.py | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/compose/config/config.py b/compose/config/config.py index be73e1dee..91f6ac9a0 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -778,6 +778,8 @@ def merge_service_dicts(base, override, version): def merge_unique_items_lists(base, override): + override = [str(o) for o in override] + base = [str(b) for b in base] return sorted(set().union(base, override)) diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index d9269ab43..3fcfec162 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -1378,6 +1378,44 @@ class ConfigTest(unittest.TestCase): 'extends': {'service': 'foo'} } + def test_merge_service_dicts_heterogeneous(self): + base = { + 'volumes': ['.:/app'], + 'ports': ['5432'] + } + override = { + 'image': 'alpine:edge', + 'ports': [5432] + } + actual = config.merge_service_dicts_from_files( + base, + override, + DEFAULT_VERSION) + assert actual == { + 'image': 'alpine:edge', + 'volumes': ['.:/app'], + 'ports': ['5432'] + } + + def test_merge_service_dicts_heterogeneous_2(self): + base = { + 'volumes': ['.:/app'], + 'ports': [5432] + } + override = { + 'image': 'alpine:edge', + 'ports': ['5432'] + } + actual = config.merge_service_dicts_from_files( + base, + override, + DEFAULT_VERSION) + assert actual == { + 'image': 'alpine:edge', + 'volumes': ['.:/app'], + 'ports': ['5432'] + } + def test_merge_build_args(self): base = { 'build': {