[mod_python] bug in apache.import_module

Huzaifa Tapal huzaifa at hostway.com
Thu Apr 28 18:22:16 EDT 2005


I think there is a bug in apache.import_module.  I am using 
apache.import_module passing in the path where I want the module 
imported from.  I am seeing a very odd result as to sometimes, the 
module that is loaded is not the right one.  Instead it loads a module 
that is of the same name but in a different directory.  Here is what is 
happening:

I have two modules of same name in 2 different directories as follows;

/home/user/dir1/moduleA
/home/user/dir123/moduleB

Lets say I restart apache and load up moduleA.  At that point there is 
an entry in sys.modules for moduleA.  Lets say then, I load up moduleB, 
now the original entry for moduleA is overwritten by this new entry.  
Now when I go back to load moduleA, I get back moduleB results. Here is why:

In apache.import_module if I pass in the path to load moduleA from 
'/home/user/dir1' and the last module was in '/home/user/dir123' then 
the check in import_module to make sure both modules aren't the same 
fails since it does a "file.startswith()" check on the path.  Since the 
path moduleA is in the path to moduleB, it loads the wrong module.

I see that somebody else had complained about this problem in mod_python 
1.3.1 but it still has not been patched.

Any ideas?

Hozi




More information about the Mod_python mailing list