﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30787	update_connections_time_zone fails with parallel tests	Justin Walters	nobody	"I have extended the DiscoverRunner to wrap `override_settings(USE_TZ=False)` around setup_databases and run_suite, in order to allow my tests and migrations to peacefully use timezone-naive test data.

I just began using the `manage.py test --parallel` to run my tests in parallel.  However, even though my tests succeed, the test runner crashes before exiting, with the below exception.  My test database does not get torn down as a result.  If I remove the `override_settings(USE_TZ=False)` the exception never occurs.

My guess is that `django.test.signals.update_connections_time_zone` does not gracefully handle the connection being closed before the function completes.  But I think it smells to just silence this exception in this function, and am worried that perhaps my own code somewhere is abusing the db connection.  Thoughts?

{{{
Traceback (most recent call last):
  File ""./manage.py"", line 15, in <module>
    execute_from_command_line(sys.argv)
  File ""/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py"", line 371, in execute_from_command_line
    utility.execute()
  File ""/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py"", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py"", line 26, in run_from_argv
    super().run_from_argv(argv)
  File ""/usr/local/lib/python3.6/site-packages/django/core/management/base.py"", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File ""/usr/local/lib/python3.6/site-packages/django/core/management/base.py"", line 335, in execute
    output = self.handle(*args, **options)
  File ""/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py"", line 59, in handle
    failures = test_runner.run_tests(test_labels)
  File ""/usr/local/lib/python3.6/site-packages/django/test/runner.py"", line 603, in run_tests
    result = self.run_suite(suite)
  File ""/code/application/test_runner.py"", line 30, in run_suite
    return super(TestRunner, self).run_suite(*args, **kwargs)
  File ""/usr/local/lib/python3.6/site-packages/django/test/utils.py"", line 343, in __exit__
    self.disable()
  File ""/usr/local/lib/python3.6/site-packages/django/test/utils.py"", line 419, in disable
    setting=key, value=new_value, enter=False)
  File ""/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py"", line 178, in send
    for receiver in self._live_receivers(sender)
  File ""/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py"", line 178, in <listcomp>
    for receiver in self._live_receivers(sender)
  File ""/usr/local/lib/python3.6/site-packages/django/test/signals.py"", line 74, in update_connections_time_zone
    conn.ensure_timezone()
  File ""/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py"", line 193, in ensure_timezone
    cursor.execute(self.ops.set_time_zone_sql(), [timezone_name])
psycopg2.OperationalError: server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
}}}"	Bug	closed	Testing framework	2.0	Normal	duplicate		justinpw@… walters_justin_peter@…	Unreviewed	0	0	0	0	0	0
