#29040: test database creation log output doesn't use consistent stream
-------------------------------------+-------------------------------------
               Reporter:  Chris      |          Owner:  nobody
  Jerdonek                           |
                   Type:             |         Status:  new
  Cleanup/optimization               |
              Component:  Testing    |        Version:  master
  framework                          |       Keywords:
               Severity:  Normal     |  stdout,stderr,database,creation
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 While troubleshooting a test issue, I ran into confusing output that I
 tracked down to
 
[https://github.com/django/django/blob/7fbb1bd00d8a3e9a834de83d36ebcbff15c18938/django/db/backends/base/creation.py#L173-L186
 `base/creation.py`] (code shown below) logging its log output to two
 different streams. This caused messages to display different from their
 actual order.

 Specifically, I was seeing the following message:

 {{{
 Got an error creating the test database: ...
 }}}

 //after// this message:

 {{{
 Destroying old test database for alias 'default'
 }}}

 when the actual order is the reverse:

 {{{#!python
 sys.stderr.write(
     "Got an error creating the test database: %s\n" % e)
 if not autoclobber:
     confirm = input(
         "Type 'yes' if you would like to try deleting the test "
         "database '%s', or 'no' to cancel: " % test_database_name)
 if autoclobber or confirm == 'yes':
     try:
         if verbosity >= 1:
             print("Destroying old test database for alias %s..." % (
                 self._get_database_display_str(verbosity,
 test_database_name),
             ))
         cursor.execute('DROP DATABASE %(dbname)s' % test_db_params)
         self._execute_create_test_db(cursor, test_db_params, keepdb)
     except Exception as e:
         sys.stderr.write(
             "Got an error recreating the test database: %s\n" % e)
         sys.exit(2)
 }}}

 I think the correct solution is for this module to be logging all output
 to `stderr` (e.g. like Python's default `logging` behavior) -- reserving
 `stdout` for structured / API output. But even just outputting all
 messages to the //same// stream would be a big improvement.

 I also think it would be a good idea to define a function like `log()`
 instead of having `print()` and `sys.stderr.write()` occur throughout.
 That would allow logging code to be controlled more centrally (aka DRY).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29040>
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/052.bed1f7a755ed320ec1e958b7b9a5a26d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to