Skip to content

Commit 424ad78

Browse files
authored
Fix for self-colliding ids on $import (#102)
* Fix for self-colliding ids on $import
1 parent 8a6eaff commit 424ad78

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ include schema_salad/tests/test_schema/*.md
44
include schema_salad/tests/test_schema/*.yml
55
include schema_salad/tests/test_schema/*.cwl
66
include schema_salad/metaschema/*
7+
global-exclude *~
78
global-exclude *.pyc

schema_salad/ref_resolver.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def __init__(self,
233233
self.url_fields = set() # type: Set[unicode]
234234
self.scoped_ref_fields = {} # type: Dict[unicode, int]
235235
self.vocab_fields = set() # type: Set[unicode]
236-
self.identifiers = set() # type: Set[unicode]
236+
self.identifiers = [] # type: List[unicode]
237237
self.identity_links = set() # type: Set[unicode]
238238
self.standalone = None # type: Optional[Set[unicode]]
239239
self.nolinkcheck = set() # type: Set[unicode]
@@ -345,7 +345,7 @@ def add_context(self, newcontext, baseuri=""):
345345
self.url_fields = set(("$schemas",))
346346
self.scoped_ref_fields = {}
347347
self.vocab_fields = set()
348-
self.identifiers = set()
348+
self.identifiers = []
349349
self.identity_links = set()
350350
self.standalone = set()
351351
self.nolinkcheck = set()
@@ -361,7 +361,7 @@ def add_context(self, newcontext, baseuri=""):
361361

362362
for key, value in self.ctx.items():
363363
if value == u"@id":
364-
self.identifiers.add(key)
364+
self.identifiers.append(key)
365365
self.identity_links.add(key)
366366
elif isinstance(value, dict) and value.get(u"@type") == u"@id":
367367
self.url_fields.add(key)
@@ -393,6 +393,8 @@ def add_context(self, newcontext, baseuri=""):
393393
for k, v in self.vocab.items():
394394
self.rvocab[self.expand_url(v, u"", scoped_id=False)] = k
395395

396+
self.identifiers.sort()
397+
396398
_logger.debug("identifiers is %s", self.identifiers)
397399
_logger.debug("identity_links is %s", self.identity_links)
398400
_logger.debug("url_fields is %s", self.url_fields)
@@ -949,6 +951,7 @@ def validate_links(self, document, base_url, all_doc_ids):
949951
"%s object %s `%s` previously defined" % (all_doc_ids[document[identifier]], identifier, relname(document[identifier]), ))
950952
else:
951953
all_doc_ids[document[identifier]] = sl.makeLead()
954+
break
952955
except validate.ValidationException as v:
953956
errors.append(sl.makeError(unicode(v)))
954957
if hasattr(document, "iteritems"):

schema_salad/validate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ClassValidationException(ValidationException):
2121

2222
def validate(expected_schema, # type: Schema
2323
datum, # type: Any
24-
identifiers=set(), # type: Set[unicode]
24+
identifiers=[], # type: List[unicode]
2525
strict=False, # type: bool
2626
foreign_properties=set() # type: Set[unicode]
2727
):
@@ -59,7 +59,7 @@ def vpformat(datum): # type: (Any) -> str
5959

6060
def validate_ex(expected_schema, # type: Schema
6161
datum, # type: Any
62-
identifiers=None, # type: Set[unicode]
62+
identifiers=None, # type: List[unicode]
6363
strict=False, # type: bool
6464
foreign_properties=None, # type: Set[unicode]
6565
raise_ex=True, # type: bool
@@ -70,7 +70,7 @@ def validate_ex(expected_schema, # type: Schema
7070
"""Determine if a python datum is an instance of a schema."""
7171

7272
if not identifiers:
73-
identifiers = set()
73+
identifiers = []
7474

7575
if not foreign_properties:
7676
foreign_properties = set()

0 commit comments

Comments
 (0)