#27751: Teardown of a PG test database fails if it is an autogenerated test_MYDB
database
-----------------------------------+------------------------------------
     Reporter:  Cynthia Kiser      |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  1.9
     Severity:  Normal             |               Resolution:
     Keywords:  database, testing  |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------

Comment (by Cynthia Kiser):

 $ tail -f /var/log/postgresql/postgresql-9.5-main.log
 {{{
 2017-01-27 09:44:28 PST [17850-1] d110example@postgres FATAL:  no
 pg_hba.conf entry for host "10.1.99.1", user "d110example", database
 "postgres", SSL on
 2017-01-27 09:44:28 PST [17851-1] d110example@postgres FATAL:  no
 pg_hba.conf entry for host "10.1.99.1", user "d110example", database
 "postgres", SSL off
 2017-01-27 09:44:28 PST [17856-1] d110example@postgres FATAL:  no
 pg_hba.conf entry for host "10.1.99.1", user "d110example", database
 "postgres", SSL on
 2017-01-27 09:44:28 PST [17857-1] d110example@postgres FATAL:  no
 pg_hba.conf entry for host "10.1.99.1", user "d110example", database
 "postgres", SSL off
 2017-01-27 09:44:29 PST [17858-1] d110example@test_d110example ERROR:
 cannot drop the currently open database
 2017-01-27 09:44:29 PST [17858-2] d110example@test_d110example STATEMENT:
 DROP DATABASE "test_d110example"
 }}}

 Output from running tests:
 {{{
 $ python manage.py test
 Creating test database for alias 'default'...
 /Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/backends/postgresql/base.py:248: RuntimeWarning:
 Normally Django will use a connection to the 'postgres' database to avoid
 running initialization queries against the production database when it's
 not needed (for example, when running tests). Django was unable to create
 a connection to the 'postgres' database and will use the default database
 instead.
   RuntimeWarning
 ..........
 ----------------------------------------------------------------------
 Ran 10 tests in 0.125s

 OK
 Destroying test database for alias 'default'...
 /Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/backends/postgresql/base.py:248: RuntimeWarning:
 Normally Django will use a connection to the 'postgres' database to avoid
 running initialization queries against the production database when it's
 not needed (for example, when running tests). Django was unable to create
 a connection to the 'postgres' database and will use the default database
 instead.
   RuntimeWarning
 Traceback (most recent call last):
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/backends/utils.py", line 62, in execute
     return self.cursor.execute(sql)
 psycopg2.OperationalError: cannot drop the currently open database


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

 Traceback (most recent call last):
   File "manage.py", line 22, in <module>
     execute_from_command_line(sys.argv)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/core/management/__init__.py", line 367, in
 execute_from_command_line
     utility.execute()
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/core/management/__init__.py", line 359, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/core/management/commands/test.py", line 29, in
 run_from_argv
     super(Command, self).run_from_argv(argv)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/core/management/base.py", line 294, in run_from_argv
     self.execute(*args, **cmd_options)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/core/management/base.py", line 345, in execute
     output = self.handle(*args, **options)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/core/management/commands/test.py", line 72, in handle
     failures = test_runner.run_tests(test_labels)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/test/runner.py", line 551, in run_tests
     self.teardown_databases(old_config)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/test/runner.py", line 526, in teardown_databases
     connection.creation.destroy_test_db(old_name, self.verbosity,
 self.keepdb)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/backends/base/creation.py", line 264, in
 destroy_test_db
     self._destroy_test_db(test_database_name, verbosity)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/backends/base/creation.py", line 283, in
 _destroy_test_db
     % self.connection.ops.quote_name(test_database_name))
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/backends/utils.py", line 64, in execute
     return self.cursor.execute(sql, params)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/utils.py", line 94, in __exit__
     six.reraise(dj_exc_type, dj_exc_value, traceback)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/utils/six.py", line 685, in reraise
     raise value.with_traceback(tb)
   File "/Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/backends/utils.py", line 62, in execute
     return self.cursor.execute(sql)
 django.db.utils.OperationalError: cannot drop the currently open database
 }}}


 ----

 Using django 1.8
 {{{
 2017-01-27 09:53:37 PST [18450-1] d110example@postgres FATAL:  no
 pg_hba.conf entry for host "10.1.99.1", user "d110example", database
 "postgres", SSL on
 2017-01-27 09:53:37 PST [18451-1] d110example@postgres FATAL:  no
 pg_hba.conf entry for host "10.1.99.1", user "d110example", database
 "postgres", SSL off
 }}}

 {{{
 (using-django1.8)$ python manage.py test
 Creating test database for alias 'default'...
 /Users/cnk/.pyenv/versions/d110example-3.5.2/lib/python3.5/site-
 packages/django/db/backends/postgresql_psycopg2/base.py:249:
 RuntimeWarning: Normally Django will use a connection to the 'postgres'
 database to avoid running initialization queries against the production
 database when it's not needed (for example, when running tests). Django
 was unable to create a connection to the 'postgres' database and will use
 the default database instead.
   RuntimeWarning

 ..........
 ----------------------------------------------------------------------
 Ran 10 tests in 0.059s

 OK
 Destroying test database for alias 'default'...
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27751#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/061.c61794f4b72d2071e13d80aef59bbb4d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to