Невозможно, кроме ValueError, брошенного mongoengine

Я пытаюсь поймать ValueError, которая происходит из-за skip параметр равен отрицательному числу. Например,

try:
    MyModel.objects.skip(-1)
except ValueError as error:
    print(error)

ничего не делает Это не ошибка с любым сообщением, и при этом он не делает ничего другого. То, что я хочу, это просто перехватить ValueError и обработать его соответствующим образом. Если я кроме TypeError (что не поднято) вместо ValueError это показывает то же самое поведение.

След:

Traceback (most recent call last):
  File "/home/admin/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/home/admin/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/admin/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/admin/.local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/viewsets.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 483, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 443, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 480, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/admin/test_serverside/essences/test_result/views.py", line 273, in get_history
    self._format_response_json(serializer.data),
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 765, in data
    ret = super(ListSerializer, self).data
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 266, in data
    self._data = self.get_initial()
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 600, in get_initial
    return self.to_representation(self.initial_data)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 683, in to_representation
    self.child.to_representation(item) for item in iterable
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 683, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/usr/local/lib/python3.6/dist-packages/mongoengine/queryset/queryset.py", line 99, in _iter_results
    self._populate_cache()
  File "/usr/local/lib/python3.6/dist-packages/mongoengine/queryset/queryset.py", line 118, in _populate_cache
    self._result_cache.append(next(self))
  File "/usr/local/lib/python3.6/dist-packages/mongoengine/queryset/base.py", line 1466, in __next__
    raw_doc = next(self._cursor)
  File "/usr/local/lib/python3.6/dist-packages/mongoengine/queryset/base.py", line 1573, in _cursor
    self._cursor_obj.skip(self._skip)
  File "/usr/local/lib/python3.6/dist-packages/pymongo/cursor.py", line 491, in skip
    raise ValueError("skip must be >= 0")
ValueError: skip must be >= 0

0 ответов

Другие вопросы по тегам