Skip to content

Commit 71623bb

Browse files
fix #700 differently - bypass the restriction against python-native data types
1 parent de32e27 commit 71623bb

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

datajoint/jobs.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
from .hash import key_hash
22
import os
33
import platform
4-
import numpy as np
54
from .table import Table
6-
from .errors import DuplicateError
75
from .settings import config
8-
from .blob import MatStruct
6+
from .errors import DuplicateError
97

108
ERROR_MESSAGE_LENGTH = 2047
119
TRUNCATION_APPENDIX = '...truncated'
1210

1311

14-
def _adapt_key_to_matstruct(key):
15-
"""
16-
Only used as a temporary measure for uninterrupted interoperability with datajoint 0.11.
17-
Will be deprecated in datajoint 0.13 when support for native python data types is accepted.
18-
:param key: a dict representing the primary key
19-
:return: converted to dj.blob.MatStruct
20-
"""
21-
return (key if config.get('enable_python_native_blobs')
22-
else np.reshape(np.rec.array((list(key.values())), names=list(key)), (1, 1)).view(MatStruct))
23-
24-
2512
class JobTable(Table):
2613
"""
2714
A base relation with no definition. Allows reserving jobs
@@ -87,10 +74,11 @@ def reserve(self, table_name, key):
8774
host=platform.node(),
8875
pid=os.getpid(),
8976
connection_id=self.connection.connection_id,
90-
key=_adapt_key_to_matstruct(key),
77+
key=key,
9178
user=self._user)
9279
try:
93-
self.insert1(job, ignore_extra_fields=True)
80+
with config(enable_pyton_native_blobs=True):
81+
self.insert1(job, ignore_extra_fields=True)
9482
except DuplicateError:
9583
return False
9684
return True
@@ -115,16 +103,17 @@ def error(self, table_name, key, error_message, error_stack=None):
115103
"""
116104
if len(error_message) > ERROR_MESSAGE_LENGTH:
117105
error_message = error_message[:ERROR_MESSAGE_LENGTH-len(TRUNCATION_APPENDIX)] + TRUNCATION_APPENDIX
118-
self.insert1(
119-
dict(
120-
table_name=table_name,
121-
key_hash=key_hash(key),
122-
status="error",
123-
host=platform.node(),
124-
pid=os.getpid(),
125-
connection_id=self.connection.connection_id,
126-
user=self._user,
127-
key=_adapt_key_to_matstruct(key),
128-
error_message=error_message,
129-
error_stack=error_stack),
130-
replace=True, ignore_extra_fields=True)
106+
with config(enable_pyton_native_blobs=True):
107+
self.insert1(
108+
dict(
109+
table_name=table_name,
110+
key_hash=key_hash(key),
111+
status="error",
112+
host=platform.node(),
113+
pid=os.getpid(),
114+
connection_id=self.connection.connection_id,
115+
user=self._user,
116+
key=key,
117+
error_message=error_message,
118+
error_stack=error_stack),
119+
replace=True, ignore_extra_fields=True)

0 commit comments

Comments
 (0)