Skip to content

Commit

Permalink
Don't report duplication for all arrays without IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Nov 21, 2019
1 parent b4b0cce commit ba14b11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
13 changes: 8 additions & 5 deletions libcove/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from flattentool import unflatten
from flattentool.schema import get_property_type_set
from jsonschema import FormatChecker, RefResolver
from jsonschema._utils import uniq
from jsonschema.exceptions import ValidationError

from .exceptions import cove_spreadsheet_conversion_error
Expand Down Expand Up @@ -66,6 +67,7 @@ def unique_ids(validator, ui, instance, schema):
if ui and validator.is_type(instance, "array"):
non_unique_ids = set()
all_ids = set()
previous_items = set()
for item in instance:
try:
item_id = item.get(id_name)
Expand All @@ -81,11 +83,12 @@ def unique_ids(validator, ui, instance, schema):
non_unique_ids.add(item_id)
all_ids.add(item_id)
else:
msg = "Array has non-unique elements"
err = ValidationError(msg, instance=instance)
err.error_id = "uniqueItems_no_ids"
yield err
return
if uniq(instance):
msg = "Array has non-unique elements"
err = ValidationError(msg, instance=instance)
err.error_id = "uniqueItems_no_ids"
yield err
return

for non_unique_id in sorted(non_unique_ids):
msg = "Non-unique {} values".format(id_name)
Expand Down
26 changes: 0 additions & 26 deletions tests/lib/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,19 +620,6 @@ def get_release_pkg_schema_obj(self):
"error_id": None,
"values": [{"path": "releases/1"}],
},
{
"message": "Array has non-unique elements",
"message_safe": "Array has non-unique elements",
"validator": "uniqueItems",
"assumption": None,
"message_type": "uniqueItems",
"path_no_number": "releases",
"header": "releases",
"header_extra": "releases",
"null_clause": "",
"error_id": "uniqueItems_no_ids",
"values": [{"path": "releases"}],
},
],
),
(
Expand Down Expand Up @@ -665,19 +652,6 @@ def get_release_pkg_schema_obj(self):
"error_id": None,
"values": [{"path": "records/1"}],
},
{
"message": "Array has non-unique elements",
"message_safe": "Array has non-unique elements",
"validator": "uniqueItems",
"assumption": None,
"message_type": "uniqueItems",
"path_no_number": "records",
"header": "records",
"header_extra": "records",
"null_clause": "",
"error_id": "uniqueItems_no_ids",
"values": [{"path": "records"}],
},
],
),
],
Expand Down

0 comments on commit ba14b11

Please sign in to comment.