﻿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
14861	Importing settings in a module that contains a logging Handler causes circular import.	donspaulding	Claude Paroz <claude@…>	"If `settings.py` contains the following config for LOGGING:

{{{
LOGGING = {
  'version': 1,
  'handlers': {
    'custom_handler': {
      'level': 'INFO',
      'class': 'myproject.logconfig.MyHandler',
    }
  }
}
}}}

and `myproject/logconfig.py` has the following line before the `MyHandler` definition:

{{{
from django.conf import settings
}}}

The dictconfig module spits out a none-too-helpful traceback:

{{{
Traceback (most recent call last):
  File ""manage.py"", line 11, in <module>
    execute_manager(settings)
  File ""/home/don/myproject/src/django/django/core/management/__init__.py"", line 438, in execute_manager
    utility.execute()
  File ""/home/don/myproject/src/django/django/core/management/__init__.py"", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/home/don/myproject/src/django/django/core/management/__init__.py"", line 252, in fetch_command
    app_name = get_commands()[subcommand]
  File ""/home/don/myproject/src/django/django/core/management/__init__.py"", line 101, in get_commands
    apps = settings.INSTALLED_APPS
  File ""/home/don/myproject/src/django/django/utils/functional.py"", line 276, in __getattr__
    self._setup()
  File ""/home/don/myproject/src/django/django/conf/__init__.py"", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File ""/home/don/myproject/src/django/django/conf/__init__.py"", line 126, in __init__
    logging_config_func(self.LOGGING)
  File ""/home/don/myproject/src/django/django/utils/dictconfig.py"", line 553, in dictConfig
    dictConfigClass(config).configure()
  File ""/home/don/myproject/src/django/django/utils/dictconfig.py"", line 352, in configure
    '%r: %s' % (name, e))
ValueError: Unable to configure handler 'custom_handler': Unable to configure handler 'custom_handler': 'module' object has no attribute 'logconfig'
}}}

The problem is easily rectified once you realize that it's a circular import.  Apart from lazily loading the logging config, I'm not even sure there's an appropriate code fix.  I'm mainly filing this bug to see if a note can be placed alongside the logging configuration docs that warns of the potential problem.  "	Bug	closed	Core (Other)	dev	Normal	fixed		percivall@…	Accepted	1	0	0	0	0	0
