Opened 14 years ago
Closed 10 years ago
#15917 closed Bug (wontfix)
Logging dictionary config works wrong at least with SMTPHandler
Reported by: | Veniamin Albaev | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Jesaja Everling | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
/django/utils/dictconfig.py:218 has method BaseConfigurator.convert() wich converts dictionaries, tuples and lists to it ConvertingDict, ConvertingType, ConvertingList analogies. But in /logging/handlers.py:808 SMTPHandler.init() method argument types checks for full equality with particular type (ex. if type(credentials) == types.TupleType).
As result it's imposiible to pass mailhost with port and credentials to SMTPHandler througth dictionary config
Attachments (1)
Change History (7)
comment:1 by , 14 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
comment:2 by , 14 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → reopened |
test.py (in attachment) fails with next configuration
LOGGING = { 'version': 1, 'disable_existing_loggers' : True, 'handlers': { 'mail': { 'level': 'DEBUG', 'class':'logging.handlers.SMTPHandler', 'mailhost': ('mailhost.test', 321), 'fromaddr': 'testuser@domain.com', 'toaddrs': ['testuser@domain.com',], 'subject': 'Test email', 'credentials': ('testuser1', 'testpassword1',), }, }, 'loggers': { 'test.logger': { 'level': 'DEBUG', 'handlers': ['mail',], 'propagate': False, }, }, }
comment:3 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
OK, I was expected an exception, actually it's rather a silent misconfiguration. I confirm that django.utils.log.dictConfig
with Python 2.6 and logging.config.dictConfig
in stock Python 2.7 behave differently.
>>> from django.utils.log import dictConfig # Django >>> dictConfig({ ... 'version': 1, ... 'handlers': { ... 'send_email': { ... 'class':'logging.handlers.SMTPHandler', ... 'mailhost': ('localhost', 25), ... 'fromaddr': 'django@example.com', ... 'toaddrs': ['django@example.com'], ... 'subject': 'oops!', ... 'credentials': ('root', 'root'), ... }, ... }, ... 'loggers': { ... 'django': { ... 'handlers':['send_email'], ... }, ... }, ... }) >>> import logging >>> handler = logging.getLogger('django').handlers[0] >>> handler.mailhost ('localhost', 25) >>> handler.mailport >>> handler.username >>> handler.password Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: SMTPHandler instance has no attribute 'password'
>>> from logging.config import dictConfig # Python 2.7 (snip - same commands as above) >>> handler.mailhost 'localhost' >>> handler.mailport 25 >>> handler.username 'root' >>> handler.password 'root'
comment:4 by , 13 years ago
Cc: | added |
---|---|
UI/UX: | unset |
I also ran into this issue, because I was trying to specify the SMPT-port (for TLS).
You are supposed to pass mailhost = (HOST, PORT) to SMTPHandler. However, as albenik said, SMTPHandler.init does type-checking which fails due to mailhost being of type django.utils.dictconfig.ConvertingTuple:
/usr/lib/python2.6/logging/handlers.py:819
if type(mailhost) == types.TupleType: self.mailhost, self.mailport = mailhost
This issue doesn't exist in Python 2.7:
/usr/lib/python2.7/logging/handlers.py:841
if isinstance(mailhost, tuple): self.mailhost, self.mailport = mailhost
comment:5 by , 12 years ago
Status: | reopened → new |
---|
comment:6 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
django.utils.log.dictConfig
now useslogging.config.dictConfig
, anddjango.utils.dictconfig
has been deprecated.- Django 1.7 and newer versions are no longer supports Python 2.6.
- Django 1.6 is now in security-fix-only mode, so I'm closing this ticket as "wontfix".
I could not reproduce this with the SVN version of Django and Python 2.6 or 2.7. The following settings load correctly:
The logging code is directly taken from Python itself, I could not find a similar issue in Python's bug tracker.
Please attach a failing test case and reopen the ticket.