Skip to content

Commit de32e27

Browse files
fix #700
1 parent f2c2969 commit de32e27

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

datajoint/connection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def translate_query_error(client_error, query):
3939
return errors.DuplicateError(*client_error.args[1:])
4040
if isinstance(client_error, client.err.IntegrityError) and client_error.args[0] == 1452:
4141
return errors.IntegrityError(*client_error.args[1:])
42-
# Syntax Errors
42+
# Syntax errors
4343
if isinstance(client_error, client.err.ProgrammingError) and client_error.args[0] == 1064:
4444
return errors.QuerySyntaxError(client_error.args[1], query)
45-
# Existence Errors
45+
# Existence errors
4646
if isinstance(client_error, client.err.ProgrammingError) and client_error.args[0] == 1146:
4747
return errors.MissingTableError(client_error.args[1], query)
4848
if isinstance(client_error, client.err.InternalError) and client_error.args[0] == 1364:
@@ -286,4 +286,3 @@ def transaction(self):
286286
raise
287287
else:
288288
self.commit_transaction()
289-

datajoint/jobs.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
from .hash import key_hash
22
import os
33
import platform
4+
import numpy as np
45
from .table import Table
5-
from .errors import DuplicateError, IntegrityError
6+
from .errors import DuplicateError
7+
from .settings import config
8+
from .blob import MatStruct
69

710
ERROR_MESSAGE_LENGTH = 2047
811
TRUNCATION_APPENDIX = '...truncated'
912

1013

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+
1125
class JobTable(Table):
1226
"""
1327
A base relation with no definition. Allows reserving jobs
@@ -73,7 +87,7 @@ def reserve(self, table_name, key):
7387
host=platform.node(),
7488
pid=os.getpid(),
7589
connection_id=self.connection.connection_id,
76-
key=key,
90+
key=_adapt_key_to_matstruct(key),
7791
user=self._user)
7892
try:
7993
self.insert1(job, ignore_extra_fields=True)
@@ -101,15 +115,16 @@ def error(self, table_name, key, error_message, error_stack=None):
101115
"""
102116
if len(error_message) > ERROR_MESSAGE_LENGTH:
103117
error_message = error_message[:ERROR_MESSAGE_LENGTH-len(TRUNCATION_APPENDIX)] + TRUNCATION_APPENDIX
104-
job_key = dict(table_name=table_name, key_hash=key_hash(key))
105118
self.insert1(
106-
dict(job_key,
107-
status="error",
108-
host=platform.node(),
109-
pid=os.getpid(),
110-
connection_id=self.connection.connection_id,
111-
user=self._user,
112-
key=key,
113-
error_message=error_message,
114-
error_stack=error_stack),
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),
115130
replace=True, ignore_extra_fields=True)

0 commit comments

Comments
 (0)