Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.1.4
-
None
-
None
Description
In publisher.py, modules are loaded using the code:
try:
module = apache.import_module(module_name,
autoreload=autoreload,
log=log,
path=[path])
except ImportError:
et, ev, etb = sys.exc_info()
- try again, using default module, perhaps this is a
- /directory/function (as opposed to /directory/module/function)
func_path = module_name
module_name = "index"
try:
module = apache.import_module(module_name,
autoreload=autoreload,
log=log,
path=[path])
except ImportError: - raise the original exception
raise et, ev, etb
The intent here being that if it can't find /directory/<module>/<function> that
it will instead look for /directory/index/<function>. Previous bug report noted
that the new func_path should be combination of module_name and existing
value of func_path, but there is another issue with this code.
The problem is that the second import should really only be tried if the first module
didn't in fact exist at all. The second import however will be attempted when any
type of ImportError occurs. This could lead to a coding error in the first module not
being detected because any such error is silently ignored.
For example, image the first module was called "page.py" and contained:
import xxx
def index():
return "page/index"
and the second module, ie., the fallback of "index.py" contained:
def page():
return "index/page"
Note that the module "xxx" does not in fact exist.
If one access the URL:
/page/index
the "import xxx" fails and raises an ImportError. This then causes "index.py"
to be loaded instead and the result is:
"index/page"
and not as desired:
"page/index".
That there was any problem with importing "page.py" is not evident as any details
of any error message are not logged.
The only possible way around this and knowing that an error occured because of
a module which wasn't there in the first place vs an error within the module being
imported is perhaps that the result of:
f, p, d = imp.find_module(parts[i], path)
in import_module() is checked somehow to see if a module could be found and if
not raise a mod_python specific exception which could be detected by publisher
as indicating a missing module which would then cause a fall through to the "index.py"
default. Ie.,
try:
f, p, d = imp.find_module(parts[i], path)
excpt ImportError:
raise ModuleNotFound()
Suggested solution not actually tried.