11from .hash import key_hash
22import os
33import platform
4- import numpy as np
54from .table import Table
6- from .errors import DuplicateError
75from .settings import config
8- from .blob import MatStruct
6+ from .errors import DuplicateError
97
108ERROR_MESSAGE_LENGTH = 2047
119TRUNCATION_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-
2512class 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