From aed032d0ac0f30e7e985f19536ac7a2cd2bc0233 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 11 Apr 2010 06:48:46 +0000 Subject: [PATCH] Fixed #13311 -- Modified the tag library import process so it doesn't mask import errors in the tag library itself. Thanks to amccurdy for the report, and Alex Gaynor for the suggested fix. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12944 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/django/template/__init__.py b/django/template/__init__.py index 0cd42cf0eb..00949d6e59 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -48,6 +48,7 @@ u'

Hello

' >>> t.render(c) u'' """ +import imp import re from inspect import getargspec @@ -979,10 +980,19 @@ def import_library(taglib_module): Verifies that the library contains a 'register' attribute, and returns that attribute as the representation of the library """ + # We need to be able to tell the difference between a tag library that + # doesn't exist, and a tag library with errors in it. + # find_module() finds, but doesn't actually load the module requested. + # If it raises ImportError, it means the module doesn't exist. + # If you then use load_module(), any ImportError is guaranteed to be + # an actual import problem with the module. + app_path, taglib = taglib_module.rsplit('.',1) + app_module = import_module(app_path) try: - mod = import_module(taglib_module) - except ImportError: + imp.find_module(taglib, app_module.__path__) + except ImportError,e: return None + mod = import_module(taglib_module) try: return mod.register except AttributeError: