InterfaceError: connection already closed - django

I'm running a celery(4.1.0) task with django(1.11.6) using psycopg2(2.7.3), getting these errors after 5-6 hour of deploying the app on production. One of the related issue on Django issue tickets. Tried various solution of reconnecting the connection using try and except, handling InterfaceError. Any help will be appreciated. Checked and Applied some of the solutions, but nothing seems to be working, Celery Worker Database Connection Pooling
Traceback
InterfaceError: connection already closed
File "billiard/pool.py", line 358, in workloop
result = (True, prepare_result(fun(*args, **kwargs)))
File "celery/app/trace.py", line 537, in _fast_trace_task
uuid, args, kwargs, request,
File "celery/app/trace.py", line 482, in trace_task
I, _, _, _ = on_error(task_request, exc, uuid)
File "celery/app/trace.py", line 330, in on_error
task, request, eager=eager, call_errbacks=call_errbacks,
File "celery/app/trace.py", line 164, in handle_error_state
call_errbacks=call_errbacks)
File "celery/app/trace.py", line 212, in handle_failure
task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
File "telemetry/tasks.py", line 29, in on_failure
save_failed_task(self, exc, task_id, args, kwargs, einfo)
File "telemetry/celery_failure.py", line 46, in save_failed_task
existing_task_first = existing_task.first()
File "django/db/models/query.py", line 564, in first
objects = list((self if self.ordered else self.order_by('pk'))[:1])
File "django/db/models/query.py", line 250, in __iter__
self._fetch_all()
File "django/db/models/query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "django/db/models/sql/compiler.py", line 882, in execute_sql
cursor = self.connection.cursor()
File "django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "django/db/backends/base/base.py", line 231, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "django/db/backends/base/base.py", line 231, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "django/db/backends/postgresql/base.py", line 220, in create_cursor
cursor = self.connection.cursor()

Related

Django on Ubuntu giving libpq version 10 error [duplicate]

This question already has answers here:
How can I solve Postgresql SCRAM authentication problem?
(17 answers)
SCRAM authentication requires libpq version 10 or above in
(3 answers)
Closed 10 days ago.
I am trying to setup a Django website on linux ubuntu with postgresql, gunicorn and nginx.
However every time I try to start the development server I get this following error:
Traceback (most recent call last):
File "/home/ubuntu/personalserver/manage.py", line 22, in <module>
main()
File "/home/ubuntu/personalserver/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 114, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in __init__
self.build_graph()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
return self._cursor()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
self.ensure_connection()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection
with self.wrap_database_errors:
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
self.connect()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: SCRAM authentication requires libpq version 10 or above
I have already tried the following fix: https://stackoverflow.com/a/62808487/15540615
such that this is my conf file:
and this is my password encryption setting:

Can’t connect to MySQL while upgrading Bitnami Review Board by rb-site

I am trying to upgrade Bitnami ReviewBoard from 3.0.1 to 3.0.2 . I have done the venv/bin/easy_install -U ReviewBoard. But when I try venv/bin/rb-site upgrade installdir/rb-sites/reviewboard/, I obtained an error of django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/opt/reviewboard-3.0.1-0/mysql/tmp/mysql.sock' (2)").
Following is the detailed log:
bash-4.2# venv/bin/rb-site upgrade ./rb-sites/reviewboard/
Traceback (most recent call last):
File "venv/bin/rb-site", line 11, in <module>
load_entry_point('ReviewBoard==3.0.2', 'console_scripts', 'rb-site')()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 1965, in main
command.run()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 1742, in run
static_media_upgrade_needed = site.get_static_media_upgrade_needed()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 503, in get_static_media_upgrade_needed
siteconfig = SiteConfiguration.objects.get_current()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/Djblets-1.0.2-py2.7.egg/djblets/siteconfig/managers.py", line 50, in g et_current
site = Site.objects.get_current()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/contrib/sites/models.py", line 47, in get_current
current_site = self.get(pk=sid)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/query.py", line 304, in get
num = len(clone)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/query.py", line 857, in _fetch_all
self._result_cache = list(self.iterator())
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/sql/compiler.py", line 713, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/models/sql/compiler.py", line 785, in execute_sql
cursor = self.connection.cursor()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 162, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 132, in _cursor
self.ensure_connection()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/__init__.py", line 115, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/django/db/backends/mysql/base.py", line 435, in get_new_connection
conn = Database.connect(**conn_params)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site -packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server th rough socket '/opt/reviewboard-3.0.1-0/mysql/tmp/mysql.sock' (2)")
bash-4.2# pwd
/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs
bash-4.2# /opt/reviewboard-3.0.1-0/ctlscript.sh status
apache not running
mysql not running
memcached not running
bash-4.2# sudo venv/bin/rb-site upgrade ./rb-sites/reviewboard/
Cannot locate wrapped file
bash-4.2# venv/bin/rb-site upgrade ./rb-sites/reviewboard/
Traceback (most recent call last):
File "venv/bin/rb-site", line 11, in <module>
load_entry_point('ReviewBoard==3.0.2', 'console_scripts', 'rb-site')()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 1965, in main
command.run()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 1742, in run
static_media_upgrade_needed = site.get_static_media_upgrade_needed()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard/cmdline/rbsite.py", line 503, in get_static_media_upgrade_needed
siteconfig = SiteConfiguration.objects.get_current()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/Djblets-1.0.2-py2.7.egg/djblets/siteconfig/managers.py", line 50, in get_current
site = Site.objects.get_current()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/contrib/sites/models.py", line 47, in get_current
current_site = self.get(pk=sid)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/query.py", line 304, in get
num = len(clone)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/query.py", line 857, in _fetch_all
self._result_cache = list(self.iterator())
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 785, in execute_sql
cursor = self.connection.cursor()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 162, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 132, in _cursor
self.ensure_connection()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 127, in ensure_connection
self.connect()
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 115, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 435, in get_new_connection
conn = Database.connect(**conn_params)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/opt/reviewboard-3.0.1-0/mysql/tmp/mysql.sock' (2)")
All operations are executed in the Bitnami Console.
Environemnts:
bash-4.2# /opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/bin/rb-site --version
rb-site 3.0.2
Python 2.7.14 (default, Dec 12 2017, 10:27:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
Installed to /opt/reviewboard-3.0.1-0/apps/reviewboard/htdocs/venv/lib/python2.7/site-packages/ReviewBoard-3.0.2-py2.7.egg/reviewboard
Currently, if I start all the required services and visite the review board, the following page is showed:
Thank you in advance!!
It was my stupid mistake! I thought upgrading should stop the MySQL service. It works perfectly after I started the MySQL service.

Django+Celery+postgresql_psycopg2 connection already closed error

After forcefully killing (kill -9) the idle db connections. Celery log showing the below error
[2016-03-08 19:28:04,765: CRITICAL/MainProcess] Task users.tasks.refresh_trend_buzz_messages[85a2430a-9a39-4979-b99d-fcaae86b3ba1] INTERNAL ERROR: InterfaceError('connection already closed',)
Traceback (most recent call last):
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/app/trace.py", line 253, in trace_task
I, R, state, retval = on_error(task_request, exc, uuid)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/app/trace.py", line 201, in on_error
R = I.handle_error_state(task, eager=eager)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/app/trace.py", line 85, in handle_error_state
}[self.state](task, store_errors=store_errors)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/app/trace.py", line 118, in handle_failure
req.id, exc, einfo.traceback, request=req,
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/backends/base.py", line 120, in mark_as_failure
traceback=traceback, request=request)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/celery/backends/base.py", line 251, in store_result
request=request, **kwargs)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/backends/database.py", line 29, in _store_result
traceback=traceback, children=self.current_task_children(request),
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/managers.py", line 42, in _inner
return fun(*args, **kwargs)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/managers.py", line 181, in store_result
'meta': {'children': children}})
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/managers.py", line 87, in update_or_create
return get_queryset(self).update_or_create(**kwargs)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/djcelery/managers.py", line 70, in update_or_create
obj, created = self.get_or_create(**kwargs)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 373, in get_or_create
return self.get(**lookup), False
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 780, in execute_sql
cursor = self.connection.cursor()
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 159, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 131, in _cursor
return self.create_cursor()
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 131, in _cursor
return self.create_cursor()
File "/home/.virtualenvs/backend/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 139, in create_cursor
cursor = self.connection.cursor()
InterfaceError: connection already closed
I'm using Django==1.6.1, celery==3.1.10, django-celery==3.1.10 and psycopg2==2.4.1
How can I fix the error ?
This is the expected behaviour. Each celery worker will open a connection to the database and try to reuse it to avoid the overhead of negotiation every time. By killing the database processes you close the connection, hence the error.
What are you trying to achieve by killing the database processes?
You need to adjust max_connections in your PostgreSQL configuration.
You will need at least 1 connection for each celery worker plus enough for any other client code.

set_autocommit got an unexpected keyword argument 'force_begin_transaction_with_broken_autocommit'

I've just upgraded to Django 1.9, and I'm getting this error, which seems to exist entirely inside the django stack, when I run tests.
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/test/runner.py", line 482, in setup_databases
self.parallel, **kwargs
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/test/runner.py", line 726, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 119, in call_command
return command.execute(*args, **defaults)
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 89, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/db/migrations/loader.py", line 176, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 56, in ensure_schema
with self.connection.schema_editor() as editor:
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 84, in __enter__
self.atomic.__enter__()
File "~/.virtualenvs/env/lib/python2.7/site-packages/django/db/transaction.py", line 184, in __enter__
connection.set_autocommit(False, force_begin_transaction_with_broken_autocommit=True)
TypeError: set_autocommit() got an unexpected keyword argument 'force_begin_transaction_with_broken_autocommit'
Ah ha! This is the error you get if you upgrade to Django 1.9 while using django-transaction-hooks and leave the transaction-hooks engine set up in settings.

connection.commit throws disk I/O error, but *only* when running script via procmail

I have a Django python script that is supposed to run when an email is received. The email is sent to procmail. The .procmailrc file in the user directory looks like this:
LOGFILE=debug.log
:0
* !^FROM_DAEMON
* !^FROM_MAILER
* !^X-[-\w]+Loop: .*
| sudo /path/to/project/process_message.sh
The process_message.sh script looks like:
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
CONTENTS=$(cat)
cd $DIR
source ./bin/activate
echo -e "$CONTENTS" | ./project/manage.py command_name
Important points:
The paths appear to be correct. Looking at debug.log, I can see the script is being called.
Permissions should not be a problem since process_message is run as root using sudo.
Running the process_message.sh works correctly
Running the process_message.sh as the email user also works
The error only occurs when run through procmail.
Here's the error stacktrace:
Traceback (most recent call last):
File "./app/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/path/to/project/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/path/to/project/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/path/to/project/local/lib/python3.4/dist-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/path/to/project/local/lib/python3.4/dist-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/path/to/project/app/communication/management/commands/process_reply.py", line 133, in handle
self.process_email(email_obj)
File "/path/to/project/app/communication/models.py", line 37, in from_email_addr
return self.from_code(code)
File "/path/to/project/app/communication/models.py", line 41, in from_code
match = self.get(...)
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/models/query.py", line 328, in get
num = len(clone)
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/models/query.py", line 144, in __len__
self._fetch_all()
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/path/to/project/local/lib/python3.4/dist-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/path/to/project/local/lib/python3.4/dist-packages/django/db/backends/sqlite3/base.py", line 318, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: disk I/O error