2

I am updating project's django version from 1.11 to django 2.0.8. Bet when I run a test which inherits from LiveServerTestCase and getting this error, which says:

sqlite3.OperationalError: database table is locked

The same error acquires on StaticLiverServerTestCase.

Traceback:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/usr/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 "/usr/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 "/usr/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/site-packages/rest_framework/viewsets.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 62, in _wrapper
    return bound_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 58, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/pipeline/source/core/api_views.py", line 21, in dispatch
    return super(CurrencyViewSet, self).dispatch(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/mixins.py", line 48, in list
    return Response(serializer.data)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py", line 765, in data
    ret = super(ListSerializer, self).data
  File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py", line 262, in data
    self._data = self.to_representation(self.instance)
  File "/usr/local/lib/python3.6/site-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/site-packages/django/db/models/query.py", line 272, in __iter__
    self._fetch_all()
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1179, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1068, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: database table is locked

What can cause this problem? Any help is appreciated, thanks!

  • this means somewhere there is also an estaiblished connection with the database. Make sure you have proper `connection.close()` and `commit` commands. Is there also a chance that you are trying to monitor the database from any other package? This also creates problem. – khaldi Aug 03 '18 at 10:57
  • do you have any with transaction.atomic(): block, check there any issue happened – Shihabudheen K M Aug 03 '18 at 11:33
  • @khaldi I called connections.close_all() and one test passed on the .pib file, which has one test. But the thing is that in my apiary.apib I have more than one test and it fails. Need to figure out, how to close connections before every dredd test which are in .pib file. My test looks like this by the way: `exit_status = call(['./node_modules/.bin/dredd', 'apiary.apib', self.url]) if exit_status == 1: sys.exit(1)` – Igoris Skinderis Aug 03 '18 at 14:26
  • You need to somehow commit your `whatever`. It's locked because it's mid transaction – ggdx Aug 03 '18 at 14:31
  • @ggdx, can you please tell me how exactly to do it, I am trying to dredd test using this code `exit_status = call(['./node_modules/.bin/dredd', 'apiary.apib', self.url]) if exit_status == 1: sys.exit(1)` – Igoris Skinderis Aug 03 '18 at 16:04
  • I try to run transaction.commit() before the code I have pasted in comment above and get this error: `django.db.transaction.TransactionManagementError: This is forbidden when an 'atomic' block is active.` – Igoris Skinderis Aug 03 '18 at 16:18
  • Here is the Django ticket tracking this: https://code.djangoproject.com/ticket/29062 – cjerdonek Feb 09 '21 at 04:44

0 Answers0