Skip to content

Commit 98c0a81

Browse files
authored
Merge pull request #773 from dimitri-yatsenko/master
fix #771 - rename `hash.key_hash` into `hash.hash_key_values`.
2 parents 6c92598 + 9962e0a commit 98c0a81

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

datajoint/hash.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from pathlib import Path
55

66

7-
def key_hash(key):
7+
def hash_key_values(mapping):
88
"""
9-
32-byte hash used for lookup of primary keys of jobs
9+
32-byte hash of the mapping's key values sorted by the key name.
10+
This is often used to convert a long primary key value into a shorter hash.
11+
For example, the JobTable in datajoint.jobs uses this function to hash the primary key of autopopulated tables.
1012
"""
1113
hashed = hashlib.md5()
12-
for k, v in sorted(key.items()):
14+
for k, v in sorted(mapping.items()):
1315
hashed.update(str(v).encode())
1416
return hashed.hexdigest()
1517

datajoint/jobs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .hash import key_hash
21
import os
2+
from .hash import hash_key_values
33
import platform
44
from .table import Table
55
from .settings import config
@@ -69,7 +69,7 @@ def reserve(self, table_name, key):
6969
"""
7070
job = dict(
7171
table_name=table_name,
72-
key_hash=key_hash(key),
72+
key_hash=hash_key_values(key),
7373
status='reserved',
7474
host=platform.node(),
7575
pid=os.getpid(),
@@ -89,7 +89,7 @@ def complete(self, table_name, key):
8989
:param table_name: `database`.`table_name`
9090
:param key: the dict of the job's primary key
9191
"""
92-
job_key = dict(table_name=table_name, key_hash=key_hash(key))
92+
job_key = dict(table_name=table_name, key_hash=hash_key_values(key))
9393
(self & job_key).delete_quick()
9494

9595
def error(self, table_name, key, error_message, error_stack=None):
@@ -107,7 +107,7 @@ def error(self, table_name, key, error_message, error_stack=None):
107107
self.insert1(
108108
dict(
109109
table_name=table_name,
110-
key_hash=key_hash(key),
110+
key_hash=hash_key_values(key),
111111
status="error",
112112
host=platform.node(),
113113
pid=os.getpid(),

0 commit comments

Comments
 (0)