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:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amylin, amylin1, jeff.allen, zyasoft
Priority: low Keywords:

Created on 2016-05-03.20:30:48 by amylin1, last changed 2018-03-22.08:14:13 by jeff.allen.

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>
_______________________________________
msg11712 (view) Author: Jeff Allen (jeff.allen) Date: 2018-02-25.16:02:15
I think Jim means like this:

PS issue2497> jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_151
Type "help", "copyright", "credits" or "license" for more information.
>>> import __builtin__
>>> __builtin__.Help
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Help'
>>> __builtin__.Help = "No!"
>>> __builtin__.Help
'No!'

Does that resolve it?
History
Date User Action Args
2018-03-22 08:14:13jeff.allensetpriority: low
milestone: Jython 2.7.0 ->
2018-02-25 16:02:15jeff.allensetnosy: + jeff.allen
messages: + msg11712
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