datajoint-python
datajoint-python copied to clipboard
improve error message when disconnected
trafficstars
When the connection to server goes away, error messages are misleading:
>>> Session()
---------------------------------------------------------------------------
DataJointError Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/IPython/core/formatters.py in __call__(self, obj)
309 method = get_real_method(obj, self.print_method)
310 if method is not None:
--> 311 return method()
312 return None
313 else:
/work/datajoint-python/datajoint/relational_operand.py in _repr_html_(self)
364 **dict(zip_longest(self.heading.blobs, [], fillvalue="'=BLOB='"))) # replace blobs with =BLOB=
365 info = self.heading.table_info
--> 366 count = len(rel)
367
368 css = """
/work/datajoint-python/datajoint/relational_operand.py in __len__(self)
458 number of tuples in the relation.
459 """
--> 460 return U().aggr(self, n='count(*)').fetch1['n']
461
462 def __bool__(self):
/work/datajoint-python/datajoint/fetch.py in __getitem__(self, item)
273 result = self._relation.proj(*attributes).fetch(**behavior)
274 if len(result) != 1:
--> 275 raise DataJointError('fetch1 should only return one tuple. %d tuples were found' % len(result))
276 return_values = tuple(
277 next(to_dicts(result[self._relation.primary_key]))
DataJointError: fetch1 should only return one tuple. 0 tuples were found
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/IPython/core/formatters.py in __call__(self, obj)
670 type_pprinters=self.type_printers,
671 deferred_pprinters=self.deferred_printers)
--> 672 printer.pretty(obj)
673 printer.flush()
674 return stream.getvalue()
/usr/local/lib/python3.5/dist-packages/IPython/lib/pretty.py in pretty(self, obj)
381 if callable(meth):
382 return meth(obj, self, cycle)
--> 383 return _default_pprint(obj, self, cycle)
384 finally:
385 self.end_group()
/usr/local/lib/python3.5/dist-packages/IPython/lib/pretty.py in _default_pprint(obj, p, cycle)
501 if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
502 # A user-provided repr. Find newlines and replace them with p.break_()
--> 503 _repr_pprint(obj, p, cycle)
504 return
505 p.begin_group(1, '<')
/usr/local/lib/python3.5/dist-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
699 """A pprint that just redirects to the normal repr function."""
700 # Find newlines and replace them with p.break_()
--> 701 output = repr(obj)
702 for idx,output_line in enumerate(output.splitlines()):
703 if idx:
/work/datajoint-python/datajoint/relational_operand.py in __repr__(self)
337
338 def __repr__(self):
--> 339 return super().__repr__() if config['loglevel'].lower() == 'debug' else self.preview()
340
341 def preview(self, limit=None, width=None):
/work/datajoint-python/datajoint/relational_operand.py in preview(self, limit, width)
349 if width is None:
350 width = config['display.width']
--> 351 tuples = rel.fetch(limit=limit)
352 columns = rel.heading.names
353 widths = {f: min(max([len(f)] + [len(str(e)) for e in tuples[f]]) + 4, width) for f in columns}
/work/datajoint-python/datajoint/fetch.py in __call__(self, **kwargs)
156 else:
157 ret = list(cur.fetchall())
--> 158 ret = np.array(ret, dtype=heading.as_dtype)
159 for blob_name in heading.blobs:
160 ret[blob_name] = list(map(unpack_, ret[blob_name]))
ValueError: size of tuple must match number of fields.
Make the message more informative and suggest a solution: re-connect.