Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cashet/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _stable_repr_to(
_visited.add(obj_id)
buf.write("{")
first = True
for item in sorted(obj, key=repr):
for item in sorted(obj, key=hash):
if not first:
buf.write(", ")
first = False
Expand All @@ -362,7 +362,7 @@ def _stable_repr_to(
_visited.add(obj_id)
buf.write("frozenset({")
first = True
for item in sorted(obj, key=repr):
for item in sorted(obj, key=hash):
if not first:
buf.write(", ")
first = False
Expand All @@ -377,7 +377,7 @@ def _stable_repr_to(
_visited.add(obj_id)
buf.write("{")
first = True
for key, val in sorted(obj.items(), key=lambda p: repr(p[0])):
for key, val in sorted(obj.items(), key=lambda p: hash(p[0])):
if not first:
buf.write(", ")
first = False
Expand Down
6 changes: 3 additions & 3 deletions src/cashet/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,20 @@ def _put_commit_row(
commit.task_def.args_hash,
commit.task_def.args_snapshot,
commit.task_def.func_source,
json.dumps(commit.task_def.dep_versions),
json.dumps(commit.task_def.dep_versions, sort_keys=True),
int(commit.task_def.cache),
commit.task_def.retries,
int(commit.task_def.force),
timeout_seconds,
commit.task_def.ttl.total_seconds() if commit.task_def.ttl else None,
json.dumps([r.hash for r in commit.input_refs]),
json.dumps([r.hash for r in commit.input_refs], sort_keys=True),
output_hash,
output_size,
output_tier,
commit.parent_hash,
commit.status.value,
commit.error,
json.dumps(commit.tags),
json.dumps(commit.tags, sort_keys=True),
commit.created_at.isoformat(),
commit.claimed_at.isoformat(),
accessed_at,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,26 @@ def identity(data: Any) -> Any:
ref2 = client.submit(identity, {1: 2})
assert ref1.hash != ref2.hash

def test_dict_insertion_order_invariant(self, client: Client) -> None:
def identity(data: Any) -> Any:
return data

d1 = {"x": 1, "y": 2, "z": 3}
d2 = {"z": 3, "y": 2, "x": 1}
ref1 = client.submit(identity, d1)
ref2 = client.submit(identity, d2)
assert ref1.hash == ref2.hash

def test_set_insertion_order_invariant(self, client: Client) -> None:
def identity(data: Any) -> Any:
return data

s1 = {"a", "b", "c"}
s2 = {"c", "b", "a"}
ref1 = client.submit(identity, s1)
ref2 = client.submit(identity, s2)
assert ref1.hash == ref2.hash


class TestRecursiveStructures:
def test_recursive_list_does_not_crash(self, client: Client) -> None:
Expand Down
Loading