Opened 5 years ago

Closed 3 years ago

#17052 closed Bug (wontfix)

dictConfig does not correctly handle absolute imports

Reported by: David Cramer Owned by: nobody
Component: Utilities Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When you have a module, say foo.bar.logging.Handler, and you try to register that with dictConfig it will cause an import error due to the way the recursive importing was implemented.

While we're not using Django for this, we are using logutils (which is still the same code):

https://github.com/django/django/blob/master/django/utils/dictconfig.py#L157

We patched it by simply using import correctly:

class NotBrokenDictConfig(logutils.dictconfig.DictConfigurator):
    def resolve(self, s):
        module, cls_name = s.rsplit('.', 1)
        return getattr(self.importer(module, {}, {}, [cls_name]), cls_name)

See also https://github.com/dcramer/raven/issues/4

Change History (4)

comment:1 Changed 5 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

To clarify: you appear to be reporting an issue with dictconfig itself -- is this correct? If so, has it been reported and/or fixed in Python's native dictconfig?

Django's dictconfig is a literal copy of the one included in Python, included verbatim to ensure compatibility across Python versions. If there's a problem with the version bundled with Django, the preferred fix is to update to a new verbatim copy, not to patch Django's version.

comment:2 Changed 5 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

As this query shows, this wasn't reported in Python's bug tracker yet.

We'll have to backport the fix from Python eventually, so I'm marking this as accepted.

Last edited 5 years ago by Aymeric Augustin (previous) (diff)

comment:3 Changed 4 years ago by Aymeric Augustin

Component: UncategorizedUtilities

comment:4 Changed 3 years ago by Tim Graham

Resolution: wontfix
Status: newclosed

Marking as won't fix since our copy of dictconfig is deprecated.

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