Issue2497

classification
Title: NameError: global name 'AdminConfig' is not defined in jython 2.7
Type: behaviour Severity: critical
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.0
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amylin, amylin1, zyasoft
Priority: Keywords:

Created on 2016-05-03.20:30:48 by amylin1, last changed 2017-02-27.04:45:05 by zyasoft.

Files
File name Uploaded Description Edit Remove
unnamed amylin, 2016-09-09.14:59:58
Messages
msg10852 (view) Author: (amylin1) Date: 2016-05-03.20:30:47
I have 2 scripts: Test1.py and Test2.py.  Test2.py import Test1 and Test1.py simply invokes WebSphere wsadmin AdminConfig object and it works fine with jython 2.1, but it fails with jython 2.7.

Test1.py:

def print1():
    print "I am Test1"
    cell = AdminConfig.list('Cell')
    print "cell " + cell

Test2.py:

import Test1

def print2():
        Test1.print1()
        print "I am Test2"
        nodes = AdminConfig.list('Node')
        print nodes

print2()


In jython 2.1, we have hardcoded in wsadmin code to retrieve each Adminxxxx objects from the __built__in such as:

mgr.exec("jython", "", -1, -1, "from org.python.core import __builtin__");
mgr.exec("jython", "", -1, -1, "__builtin__.Help = Help");
mgr.exec("jython", "", -1, -1, "__builtin__.AdminControl = AdminControl");
mgr.exec("jython", "", -1, -1, "__builtin__.AdminConfig = AdminConfig");
mgr.exec("jython", "", -1, -1, "__builtin__.AdminApp = AdminApp");
mgr.exec("jython", "", -1, -1, "__builtin__.AdminTask = AdminTask");

But it does not work in jython 2.7.  

We will get the NameError: global name 'AdminConfig' is not defined:

WASX7017E: Exception received while running file "c:/test2.py"; exception information: com.ibm.bsf.BSFException: excepti
on from Jython:
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "<string>", line 9, in print2
  File "c:\xx1617.02\WebSphere\AppServer_2\profiles\Dmgr01\bin\Test1.py", line 21, in print1
    cell = AdminConfig.list('Cell')
NameError: global name 'AdminConfig' is not defined


If I add the line in Test1.py to get AdminConfig object from sys._getframe(1).f_locals['AdminConfig'], it works fine.

Test1.py:

AdminConfig = sys._getframe(1).f_locals['AdminConfig']

def print1():
    print "I am Test1"
    cell = AdminConfig.list('Cell')
    print "cell " + cell


I tried to call the same jython command in wsadmin code, but it does not work:

mgr.exec("jython", "import sys", 0, 0, "import sys"); 

mgr.exec("jython", "", -1, -1, "AdminConfig = sys._getframe(0).f_locals['AdminConfig']");
mgr.exec("jython", "", -1, -1, "AdminApp = sys._getframe(0).f_locals['AdminApp']");
mgr.exec("jython", "", -1, -1, "AdminControl = sys._getframe(0).f_locals['AdminControl']");
mgr.exec("jython", "", -1, -1, "AdminTask = sys._getframe(0).f_locals['AdminTask']");
mgr.exec("jython", "", -1, -1, "Help = sys._getframe(0).f_locals['Help']"); 


Can anyone look at this bug quickly as we will ship jython 2.7 in WebSphere Application Server V9 and it will impact our customers to use modules (import a module).   Why it can't no longer get wsadmin Adminxxxx object from __builtin__?
msg10948 (view) Author: Jim Baker (zyasoft) Date: 2016-09-08.23:47:21
I believe the solution is to use the builtins Python module, instead of reaching into Jython's runtime.

There are other solutions for supporting global data in Jython, scoped as necessary.
msg10949 (view) Author: (amylin) Date: 2016-09-09.15:00:00
Jim,

Do you have example how to use builtin python module to solve this issue?  

Regards,

Amy Lin
WebSphere Scripting/ConfigService Development/Scripting Architect
amylin@us.ibm.com
Phone: 286-7245, T/L: 363-7245

From:   Jim Baker <report@bugs.jython.org>
To:     Amy Lin/Austin/IBM@IBMUS
Date:   09/08/2016 06:47 PM
Subject:        [issue2497] NameError: global name 'AdminConfig' is not 
defined in jython 2.7

Jim Baker added the comment:

I believe the solution is to use the builtins Python module, instead of 
reaching into Jython's runtime.

There are other solutions for supporting global data in Jython, scoped as 
necessary.

_______________________________________
Jython tracker <report@bugs.jython.org>
<http://bugs.jython.org/issue2497>
_______________________________________
History
Date User Action Args
2017-02-27 04:45:05zyasoftsetassignee: zyasoft ->
2016-09-14 16:17:42zyasoftsetassignee: zyasoft
2016-09-09 15:00:00amylinsetfiles: + unnamed
nosy: + amylin
messages: + msg10949
2016-09-08 23:47:22zyasoftsetmessages: + msg10948
2016-07-29 21:29:16zyasoftsetnosy: + zyasoft
2016-05-03 20:34:19amylin1settitle: NameError: global name 'AdminConfig' is not defined -> NameError: global name 'AdminConfig' is not defined in jython 2.7
2016-05-03 20:30:49amylin1create