Issue1629

classification
Title: Jython+django-jython - no module named site
Type: behaviour Severity: major
Components: Library Versions: Jython 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amak Nosy List: akruis, amak, joseflores, rafanunes
Priority: Keywords: patch

Created on 2010-07-08.18:47:55 by rafanunes, last changed 2013-03-04.08:58:44 by amak.

Files
File name Uploaded Description Edit Remove
issue1629_fix.diff akruis, 2010-07-22.08:06:19
Messages
msg5883 (view) Author: Rafael Nunes (rafanunes) Date: 2010-07-08.18:47:53
I have followed the install instructions for the latest versions of
the following: jython (version: jython-2.5.2b1), django (1.2.1) and
jython-django (version 1.1.1) and have built a war of my very simple
test application.

Oh i built the war on my linux box and have tested in tomcat on both
windows and linux machines. When i went to the url i got a 500
exception:

javax.servlet.ServletException: Exception creating modjy servlet:
ImportError: No module named site

        com.xhaus.modjy.ModjyJServlet.init(ModjyJServlet.java:124)
        javax.servlet.GenericServlet.init(GenericServlet.java:211)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
105)
        org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
541)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
148)
        org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
869)
        org.apache.coyote.http11.Http11BaseProtocol
$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:
664)

org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:
527)

org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:
80)
        org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadPool.java:684)
        java.lang.Thread.run(Thread.java:619)
msg5899 (view) Author: Anselm Kruis (akruis) Date: 2010-07-15.13:51:06
First, the version is 2.5.2b1 not 2.5b1.

Secondly, I can confirm the bug. Not only with 2.5.2b1 but also with a development build of SVN Rev 7056. Jython 2.5.1 works fine.
msg5916 (view) Author: Anselm Kruis (akruis) Date: 2010-07-21.12:11:54
The bug is clearly introduced by the change from SVN rev 6858 to rev 6859. This commit changes com/xhaus/modjy/ModjyJServlet.java only. The SVN log message reads:

------------------------------------------------------------------------
r6859 | amak | 2009-10-15 19:40:22 +0200 (Do, 15. Okt 2009) | 1 Zeile

Checking in support for loading site-packages, through the use of imp.load("site"). Controlled with a "load_site_packages" option, which defaults to true.
------------------------------------------------------------------------

Therefore tit should be possible to work around this bug by setting the servlet or webapp parameter "load_site_packages" to "0". 

But what is the real cause of this problem. The relevant part of the code change is the addition of

import org.python.core.imp;
...
imp.load("site");

The static method imp.load fails to load the "site" module. Currently I do not know, why it fails to load site.py, because the site.py file is present.
msg5917 (view) Author: Anselm Kruis (akruis) Date: 2010-07-22.08:06:18
The exception is indeed caused, by imp.load not finding site.py. The problem is, that sys.path is not yet properly initialized, when imp.load("site.py") is invoked. This happens, if jython is embedded within the WAR archive. In this case, the method ModjyJServlet#processPythonLib sets up sys.path to the location of the jython files within the extracted WAR archive. Currently this method is called immediately after importing "site.py". The fix simply calls processPythonLib before checkSitePackages.

I'm not sure, if we need an unit test for this bug and how to set up such a test.
msg5918 (view) Author: Alan Kennedy (amak) Date: 2010-07-22.09:20:17
I will examine this very soon.
msg5926 (view) Author: Jose Flores (joseflores) Date: 2010-07-26.22:20:56
A workaround while the new beta is released is to manually update de web.xml defining the python.home variable, and creating a pth file pointing the project being deployed.

I think a fix is needed for the war.py in order to doing those settings.
msg5927 (view) Author: Jose Flores (joseflores) Date: 2010-07-26.22:23:58
It would be something like this 	
<init-param>
      <param-name>python.home</param-name>
      <param-value>WEB-INF/lib-python</param-value>
</init-param>

and the pth file under lib-python.
msg5934 (view) Author: Alan Kennedy (amak) Date: 2010-08-01.12:53:00
Fixed in r7083.

This was an obvious bug: site.py can not be loaded without first setting up the path correctly.

As for unittests, ideally this should have failed existing tests. I am still researching why it didnt.
msg7897 (view) Author: Alan Kennedy (amak) Date: 2013-03-04.08:58:44
Updating version
History
Date User Action Args
2013-03-04 08:58:44amaksetmessages: + msg7897
versions: + Jython 2.5, - 2.5.2b1
2010-08-01 12:53:01amaksetstatus: open -> closed
resolution: fixed
messages: + msg5934
2010-07-26 22:23:59josefloressetmessages: + msg5927
2010-07-26 22:20:56josefloressetnosy: + joseflores
messages: + msg5926
2010-07-22 09:20:18amaksetassignee: amak
messages: + msg5918
nosy: + amak
2010-07-22 08:06:20akruissetfiles: + issue1629_fix.diff
keywords: + patch
messages: + msg5917
2010-07-21 12:11:56akruissetmessages: + msg5916
2010-07-15 13:51:08akruissetnosy: + akruis
messages: + msg5899
severity: normal -> major
versions: + 2.5.2b1, - 2.5b1
2010-07-08 18:47:55rafanunescreate