1
1
from .hash import key_hash
2
2
import os
3
3
import platform
4
- import numpy as np
5
4
from .table import Table
6
- from .errors import DuplicateError
7
5
from .settings import config
8
- from .blob import MatStruct
6
+ from .errors import DuplicateError
9
7
10
8
ERROR_MESSAGE_LENGTH = 2047
11
9
TRUNCATION_APPENDIX = '...truncated'
12
10
13
11
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
-
25
12
class JobTable (Table ):
26
13
"""
27
14
A base relation with no definition. Allows reserving jobs
@@ -87,10 +74,11 @@ def reserve(self, table_name, key):
87
74
host = platform .node (),
88
75
pid = os .getpid (),
89
76
connection_id = self .connection .connection_id ,
90
- key = _adapt_key_to_matstruct ( key ) ,
77
+ key = key ,
91
78
user = self ._user )
92
79
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 )
94
82
except DuplicateError :
95
83
return False
96
84
return True
@@ -115,16 +103,17 @@ def error(self, table_name, key, error_message, error_stack=None):
115
103
"""
116
104
if len (error_message ) > ERROR_MESSAGE_LENGTH :
117
105
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