Opened 4 years ago

Closed 4 years ago

#16585 closed Bug (invalid)

BaseConfigurator importer logical mistake

Reported by: Alexandr Owned by: nobody
Component: Core (Other) Version: 1.3
Severity: Normal Keywords: logging, dictconfig
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

"BaseConfigurator.importer" method doesn't correct work, because __import__ get module name as first argument, but when we use self.importer we give class instance as first argument.

As result "BaseConfigurator.resolve" (line 178) raise ValueError with message "__import__() argument 1 must be string, not DictConfigurator"

https://code.djangoproject.com/browser/django/trunk/django/utils/dictconfig.py#L151

Attachments (1)

importer_patch.diff (925 bytes) - added by Alexandr 4 years ago.
Ticket patch variant

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by Alexandr

Ticket patch variant

comment:1 Changed 4 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This module is copy-pasted from python 2.7: http://svn.python.org/projects/python/branches/release27-maint/Lib/logging/config.py

It's surprising to find such an obvious mistake in Python itself, and if the bug is confirmed, it should be filed in Python's bug tracker too.

I'm a bit wary of reports based on code inspection; could you explain the situation where you hit this bug?

comment:2 Changed 4 years ago by Alexandr

I tried to debug my django script (use multiprocessing module) with winpdb support.

For test I run command: env/bin/winpdb ./manage.py help

As result I get an error when django load "django.utils.log.CallbackFilter":
ValueError with message "__import__() argument 1 must be string, not DictConfigurator

At line: https://code.djangoproject.com/browser/django/trunk/django/utils/dictconfig.py#L165
variable used = 'django'
but self.importer(used) get self (DictConfigurator) as first argument.

After I patched importer its work well without errors.

comment:3 Changed 4 years ago by Alexandr

Create empty django project: django-admin createproject bbbtest
Create virtualenv with django and winpdb/rpdb2.
Execute env/bin/rpdb2 ./manage.py help
Input "go" several times and you get traceback

Full traceback

/tmp/bbbtest/venv/src/django/django/conf/__init__.py:75: DeprecationWarning: The ADMIN_MEDIA_PREFIX setting has been removed; use STATIC_URL instead.
  "use STATIC_URL instead.", DeprecationWarning)
Traceback (most recent call last):
  File "/tmp/bbbtest/venv/lib/python2.6/site-packages/rpdb2.py", line 14499, in <module>
    ret = rpdb2.main()
  File "/tmp/bbbtest/venv/lib/python2.6/site-packages/rpdb2.py", line 14470, in main
    StartServer(_rpdb2_args, fchdir, _rpdb2_pwd, fAllowUnencrypted, fAllowRemote, secret)
  File "/tmp/bbbtest/venv/lib/python2.6/site-packages/rpdb2.py", line 14220, in StartServer
    imp.load_source('__main__', _path)    
  File "/tmp/bbbtest/manage.py", line 11, in <module>
    execute_manager(settings)
  File "/tmp/bbbtest/venv/src/django/django/core/management/__init__.py", line 442, in execute_manager
    utility.execute()
  File "/tmp/bbbtest/venv/src/django/django/core/management/__init__.py", line 368, in execute
    sys.stdout.write(self.main_help_text() + '\n')
  File "/tmp/bbbtest/venv/src/django/django/core/management/__init__.py", line 239, in main_help_text
    commands = get_commands().keys()
  File "/tmp/bbbtest/venv/src/django/django/core/management/__init__.py", line 101, in get_commands
    apps = settings.INSTALLED_APPS
  File "/tmp/bbbtest/venv/src/django/django/utils/functional.py", line 172, in inner
    self._setup()
  File "/tmp/bbbtest/venv/src/django/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/tmp/bbbtest/venv/src/django/django/conf/__init__.py", line 145, in __init__
    logging_config_func(self.LOGGING)
  File "/tmp/bbbtest/venv/src/django/django/utils/dictconfig.py", line 553, in dictConfig
    dictConfigClass(config).configure()
  File "/tmp/bbbtest/venv/src/django/django/utils/dictconfig.py", line 339, in configure
    'filter %r: %s' % (name, e))
ValueError: Unable to configure filter 'require_debug_false': __import__() argument 1 must be string, not DictConfigurator

comment:4 Changed 4 years ago by Alexandr

I think rpbd2 replace __import__, and importer begin as class instance method.

comment:5 Changed 4 years ago by aaugustin

  • Resolution set to invalid
  • Status changed from new to closed

So it looks like there's an incompatibility between winpdb/rpdb2 and Python 2.7's logging library, and this incompatibility happens to show up in the copy of the logging library shipped with Django.

In my opinion, if winpdb/rpdb2 isn't compatible with Python's standard library, it's a bug in winpdb/rpdb2, not in Django. Hence, I will mark this ticket as invalid.

Note: See TracTickets for help on using tickets.
Back to Top