diff --git a/umap/tests/test_merge_conflicts.py b/umap/tests/test_merge_conflicts.py index c26e0ddc4..cde4eee88 100644 --- a/umap/tests/test_merge_conflicts.py +++ b/umap/tests/test_merge_conflicts.py @@ -1,3 +1,5 @@ +import pytest + from umap.utils import merge_conflicts @@ -48,14 +50,18 @@ def test_removing_same_element(): def test_removing_changed_element(): - assert merge_conflicts(["A", "B"], ["A", "C"], ["A"]) is False + with pytest.raises(ValueError): + merge_conflicts(["A", "B"], ["A", "C"], ["A"]) def test_changing_removed_element(): - assert merge_conflicts(["A", "B"], ["A"], ["A", "C"]) is False + with pytest.raises(ValueError): + merge_conflicts(["A", "B"], ["A"], ["A", "C"]) def test_changing_same_element(): - assert merge_conflicts(["A", "B"], ["A", "D"], ["A", "C"]) is False + with pytest.raises(ValueError): + merge_conflicts(["A", "B"], ["A", "D"], ["A", "C"]) # Order does not count - assert merge_conflicts(["A", "B", "C"], ["B", "D", "A"], ["A", "E", "B"]) is False + with pytest.raises(ValueError): + merge_conflicts(["A", "B", "C"], ["B", "D", "A"], ["A", "E", "B"]) diff --git a/umap/utils.py b/umap/utils.py index 249280687..9562b0722 100644 --- a/umap/utils.py +++ b/umap/utils.py @@ -135,16 +135,14 @@ def merge_conflicts(reference, latest, entrant): # Now make sure remaining features are still in latest version for feature in reference: - found = False for other in latest: if other == feature: - found = True break - if not found: + else: # We cannot distinguish the case where both deleted the same # element and added others, or where both modified the same # element, so let's raise a conflict by caution. - return False + raise ValueError # We can merge. for feature in reference: diff --git a/umap/views.py b/umap/views.py index 7958dc844..98ee43f21 100644 --- a/umap/views.py +++ b/umap/views.py @@ -793,12 +793,12 @@ def merge(self): with open(self.path) as f: latest = json.loads(f.read()) - merge = merge_conflicts( - reference["features"], latest["features"], entrant["features"] - ) - if merge is False: - return merge - latest["features"] = merge + try: + merge_conflicts( + reference["features"], latest["features"], entrant["features"] + ) + except ValueError: + return False # Update request data. self.request.FILES["geojson"].file = BytesIO(json.dumps(latest).encode("utf-8"))