Ticket #13334: 13334-12970.diff

File 13334-12970.diff, 1.8 KB (added by ramiro, 5 years ago)

Patch with a fix for this issue, needs tests

  • django/template/__init__.py

    diff --git a/django/template/__init__.py b/django/template/__init__.py
    a b  
    5050"""
    5151import imp
    5252import re
     53import sys
    5354from inspect import getargspec
    5455
    5556from django.conf import settings
     
    982983    """
    983984    # We need to be able to tell the difference between a tag library that
    984985    # doesn't exist, and a tag library with errors in it.
    985     # find_module() finds, but doesn't actually load the module requested.
    986     # If it raises ImportError, it means the module doesn't exist.
    987     # If you then use load_module(), any ImportError is guaranteed to be
    988     # an actual import problem with the module.
    989986    app_path, taglib = taglib_module.rsplit('.',1)
    990987    app_module = import_module(app_path)
    991988    try:
    992         imp.find_module(taglib, app_module.__path__)
    993     except ImportError,e:
    994         return None
    995     mod = import_module(taglib_module)
     989        mod = import_module(taglib_module)
     990    except ImportError:
     991        # imp.find_module() can tell us if a module exists by raising
     992        # ImportError without loading it.
     993        # Problem is it isn't compatible with templatetag libraries contained
     994        # inside eggs so we need to investigate things further if it fails
     995        # making sure to use a custom loaders if it is present.
     996        importer = sys.path_importer_cache.get(app_module.__path__[0], None) or imp
     997        try:
     998            if importer.find_module(taglib, app_module.__path__) is not None:
     999                # It is guaranteed to be an actual import problem with the module.
     1000                raise
     1001        except ImportError:
     1002            # The module doesn't exist.
     1003            return None
    9961004    try:
    9971005        return mod.register
    9981006    except AttributeError:
Back to Top