#14861: Importing settings in a module that contains a logging Handler causes
circular import.
---------------------------+------------------------------------------------
Reporter: donspaulding | Owner: nobody
Status: new | Milestone:
Component: Uncategorized | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
---------------------------+------------------------------------------------
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.
--
Ticket URL: <http://code.djangoproject.com/ticket/14861>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.