Skip to content

Commit a81abf7

Browse files
committed
fix(jsonld renderer): stable ordering
1 parent cdcadf2 commit a81abf7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

trove/render/jsonld.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,9 @@ def _list_or_single_value(self, predicate_iri: str, objectlist: list):
147147
return None
148148
else:
149149
return _only_obj
150-
if predicate_iri in _PREDICATES_OF_FLEXIBLE_CARDINALITY:
151-
return (
152-
objectlist
153-
if len(objectlist) != 1
154-
else objectlist[0]
155-
)
156-
return objectlist
150+
if predicate_iri in _PREDICATES_OF_FLEXIBLE_CARDINALITY and len(objectlist) == 1:
151+
return objectlist[0]
152+
return sorted(objectlist, key=_naive_sort_key)
157153

158154
@contextlib.contextmanager
159155
def __visiting(self, iri: str):
@@ -165,3 +161,8 @@ def __visiting(self, iri: str):
165161

166162
def __already_visiting(self, iri: str) -> bool:
167163
return bool(self.__visiting_iris and (iri in self.__visiting_iris))
164+
165+
166+
def _naive_sort_key(jsonable_obj):
167+
_json = json.dumps(jsonable_obj)
168+
return (len(_json), _json)

0 commit comments

Comments
 (0)