|
1 | 1 | from .hash import key_hash
|
2 | 2 | import os
|
3 | 3 | import platform
|
| 4 | +import numpy as np |
4 | 5 | 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 |
6 | 9 |
|
7 | 10 | ERROR_MESSAGE_LENGTH = 2047
|
8 | 11 | TRUNCATION_APPENDIX = '...truncated'
|
9 | 12 |
|
10 | 13 |
|
| 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 | + |
11 | 25 | class JobTable(Table):
|
12 | 26 | """
|
13 | 27 | A base relation with no definition. Allows reserving jobs
|
@@ -73,7 +87,7 @@ def reserve(self, table_name, key):
|
73 | 87 | host=platform.node(),
|
74 | 88 | pid=os.getpid(),
|
75 | 89 | connection_id=self.connection.connection_id,
|
76 |
| - key=key, |
| 90 | + key=_adapt_key_to_matstruct(key), |
77 | 91 | user=self._user)
|
78 | 92 | try:
|
79 | 93 | self.insert1(job, ignore_extra_fields=True)
|
@@ -101,15 +115,16 @@ def error(self, table_name, key, error_message, error_stack=None):
|
101 | 115 | """
|
102 | 116 | if len(error_message) > ERROR_MESSAGE_LENGTH:
|
103 | 117 | 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)) |
105 | 118 | 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), |
115 | 130 | replace=True, ignore_extra_fields=True)
|
0 commit comments