# Confusing Jython ImportError/NameError

**URL:** <https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [November 7, 2023, 9:03pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626 "2023-11-07T21:03:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [November 7, 2023, 9:03pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/1 "2023-11-07T21:03:49Z")

</div>

I was editing some Perspective views and scripts and one of the code paths started throwing this exception:

```auto
Traceback (most recent call last): 
File "<function:onMessageReceived>", line 16, in onMessageReceived 
File "<module:shared.alarm_groups>", line 243, in get_multiple_alarm_group_tables 
ImportError: Error loading module subgroups: Traceback (most recent call last): 
File "<module:shared.subgroups>", line 88, in <module> NameError: name '_[88_29]' is not defined

```

I'm assuming that `_[88_29]` is some sort of dynamic variable reference, presumably from line 88 column 29? Well, this is line 88:

```auto
RESTRICTED_GROUP_IDS = set([shared.userdb.get_group_id_from_shortname(x) for x in RESTRICTED_GROUP_NAMES])

```

Column 29 is that space between the `[` and `shared`.

What the heck is going on here? Is this just Jython badly expressing some sort of syntax error? I wasn't changing anything in this particular file, so that feels unlikely to me, but I can't figure out what else could be happening.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [November 7, 2023, 9:34pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/2 "2023-11-07T21:34:43Z")

</div>

Check the definition of `RESTRICTED_GROUP_NAMES`, you'll probably find an item in there that is missing its quotes.  
Edit: welp 🙃

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [November 7, 2023, 9:35pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/3 "2023-11-07T21:35:56Z")

</div>

I probably should have included that ... it's defined on line 87 right above:

```auto
RESTRICTED_GROUP_NAMES = set(['foo'])
RESTRICTED_GROUP_IDS = set([shared.userdb.get_group_id_from_shortname(x) for x in RESTRICTED_GROUP_NAMES])

```

It's pretty simple. ☹

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 7, 2023, 9:37pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/4 "2023-11-07T21:37:41Z")

</div>

The exception isn't complaining about a value, it's complaining about a variable name. Somewhere, a variable has a name of `_88_29`

Example:

```auto
print(b)
Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
NameError: name 'b' is not defined

```

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [November 7, 2023, 9:40pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/5 "2023-11-07T21:40:05Z")

</div>

I can promise you with total certainty that there is no variable named `_88_29` anywhere in any of our projects. I am assuming it is an un-named short-term variable that the Jython interpreter auto-generated a name for based on the line/column location. But even that doesn't explain what is failing .... 😢

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [November 7, 2023, 9:41pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/6 "2023-11-07T21:41:59Z")

</div>

Double check the code for `shared.userdb.get_group_id_from_shortname(x)`? Maybe an accidental extra quote somewhere?

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [November 7, 2023, 9:49pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/7 "2023-11-07T21:49:21Z")

</div>

I did start looking down at `get_group_id_from_shortname` but it looks clean and I also haven't changed that file in a few days and it's been working fine from everywhere else. A stronger clue is that just today I was changing the `shared.alarm_groups` script file which happens to be the thing just _above_ this in the stack trace. I haven't found any syntax errors in there yet, but I'm more suspicious of that file...

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2023, 11:48pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/8 "2023-11-07T23:48:31Z")

</div>

This a rare jython bug that has been around forever. Too elusive for me to figure out, but definitely a jython bug. Make a tiny, inconsequential edit to the affected file and save the project.

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [November 8, 2023, 2:23pm UTC](https://forum.inductiveautomation.com/t/confusing-jython-importerror-nameerror/81626/9 "2023-11-08T14:23:37Z")

</div>

That appears to have done it. The error is no longer happening... Thank you.
