#30787 closed Bug (duplicate)
update_connections_time_zone fails with parallel tests
Reported by: | Justin Walters | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 2.0 |
Severity: | Normal | Keywords: | |
Cc: | justinpw@…, walters_justin_peter@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
This should be fixed by 7071f8f2729295b0da77b6c651966dc32c71f1ab (#30193) which is part of the upcoming 3.0 release.
You can confirm it's the case by trying it out against the currently released alpha by installing it from pypi
pip install Django==3.0a1
.Please reopen this ticket if it's not the case.