# Gateway Script Error: super(type, obj): obj must be an instance or subtype of type

**URL:** <https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [September 16, 2021, 5:48pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042 "2021-09-16T17:48:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 16, 2021, 5:48pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/1 "2021-09-16T17:48:38Z")

</div>

I have a timer event script that calls a project script. On saving the project, thus restarting the gateway scripts, I occasionally get this error in the log. Subsequent events seem to work as desired. Is this an artifact of restarting while a longer-running script is in the middle of running? It’s on a dedicated thread.

```nohighlight
com.inductiveautomation.ignition.common.script.JythonExecException: TypeError: super(type, obj): obj must be an instance or subtype of type
at org.python.core.Py.TypeError(Py.java:236)
at org.python.core.PySuper.supercheck(PySuper.java:96)
at org.python.core.PySuper.super ___init__ (PySuper.java:51)
at org.python.core.PySuper$exposed ___new__.createOfType(Unknown Source)
at org.python.core.PyOverridableNew.new_impl(PyOverridableNew.java:12)
at org.python.core.PyType.invokeNew(PyType.java:1119)
at org.python.core.PyType.type ___call__ (PyType.java:2399)
at org.python.core.PyType. __call__ (PyType.java:2389)
at org.python.core.PyObject. __call__ (PyObject.java:477)
at org.python.core.PyObject. __call__ (PyObject.java:481)
at org.python.pycode._pyx77. __getitem__ $30(:171)
at org.python.pycode._pyx77.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:150)
at org.python.core.PyFunction. __call__ (PyFunction.java:426)
at org.python.core.PyMethod. __call__ (PyMethod.java:141)
at org.python.core.PyMethod. __call__ (PyMethod.java:132)
at org.python.core.PyListDerived. __getitem__ (PyListDerived.java:959)
at org.python.pycode._pyx74.push$1(:121)
at org.python.pycode._pyx74.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:150)
at org.python.core.PyFunction. __call__ (PyFunction.java:426)
at org.python.pycode._pyx72.f$0(:1)
at org.python.pycode._pyx72.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1687)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:800)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:680)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:746)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:661)
at com.inductiveautomation.ignition.common.script.TimerScriptTask.run(TimerScriptTask.java:92)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.runAndReset(Unknown Source)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException: TypeError: super(type, obj): obj must be an instance or subtype of type

```

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [August 3, 2022, 3:53am UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/2 "2022-08-03T03:53:34Z")

</div>

I get this error pretty regularly when I save a project too.  
The error is pointing at a problem with python inheritance but it all works fine.  
It would be good to eliminate it.  
Can anyone shed light onto what’s causing it and how to get rid of it?

---

<div class="post-metadata">

**Author:** ![Michael\_Lindon1](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Michael\_Lindon1](https://forum.inductiveautomation.com/u/Michael_Lindon1)\
**Post date:** [June 14, 2023, 9:18pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/3 "2023-06-14T21:18:46Z")

</div>

Rezing this old post.

I have been receiving this error for quite some time and have tried to ignore it, but it is becoming a nuisance. I read into it and it sounds like it has to do with caching of the script objects in Jython/Ignition memory, following a script change it can cause class referencing errors due to the cache not being reloaded appropriately. But that's as far as I have gotten.

Anyone end up finding a solution to this issue?

Edit: Making grammar more good.

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [June 14, 2023, 10:53pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/4 "2023-06-14T22:53:38Z")

</div>

I've never found a solution and just put up with it. Would be great to get rid of it.

---

<div class="post-metadata">

**Author:** ![Michael\_Lindon](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Michael\_Lindon](https://forum.inductiveautomation.com/u/Michael_Lindon)\
**Post date:** [June 15, 2023, 2:10pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/5 "2023-06-15T14:10:08Z")

</div>

This does not bring me joy

---

<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:** [June 15, 2023, 2:16pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/6 "2023-06-15T14:16:40Z")

</div>

I've never seen this error. _ **Ever** _.

I am also paranoid about jython scripting memory leaks. If you are handing a jython class to any platform java functions as listeners, or otherwise persisting jython code objects across project saves, you are likely leaking memory and screwing up your class hierarchy. Which would make this error plausible (when the class you are working with has a stale version stuck in memory and your fresh code is trying to use it).

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 15, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/7 "2023-06-15T14:42:33Z")

</div>

Thanks, Phil. It does beg my original question, as I don't use any extra listeners.

> [@JordanCClark](#):
>
> Is this an artifact of restarting while a longer-running script is in the middle of running?

Would an already running script persist across a save? I would think it's probable, considering what you just posted.

Heck, at this point, I don't even remember the offending script. 🤨

---

<div class="post-metadata">

**Author:** ![Michael\_Lindon](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Michael\_Lindon](https://forum.inductiveautomation.com/u/Michael_Lindon)\
**Post date:** [June 15, 2023, 3:17pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/8 "2023-06-15T15:17:58Z")

</div>

Do you use much OO programming and inheritance? If not, you would probably never run into this issue. This seems to occur when I have multiple levels of inheritance and at least one of the inherited objects comes from a separate script, thus the desyncing on save, because I don't think Ignition/Jython dumps script classes from memory for scripts that weren't change. Which means you have a new class referencing an old one and for some reason this causes an isinstance error as mentioned here.

[super() function in Python raises a TypeError | Thomas Cokelaer's blog (thomas-cokelaer.info)](http://thomas-cokelaer.info/blog/2011/09/382/)

Reading further, supposedly this post has a solution, but haven't implemented yet, will report back if it does.  
[Another super() wrinkle – raising TypeError | Things Python (wordpress.com)](https://thingspython.wordpress.com/2010/09/27/another-super-wrinkle-raising-typeerror/)

Per your comments on hierarchy and memory leaks, never had issues with hierarchy or memory leaks with classes. Except the one time I was caching high use object instances and didn't label them correctly.

---

<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:** [June 15, 2023, 3:38pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/9 "2023-06-15T15:38:05Z")

</div>

> [@JordanCClark](#):
>
> Would an already running script persist across a save?

Yes. A project save does not kill off any running threads, and does not replace the code within them. The memory of the entire old interpreter, with old objects, is stuck in process memory until the thread finishes.

If you are using `system.util.getGlobals()` and friends, or attaching jython classes to SDK APIs, old and new objects can mix. (And old objects can get stuck.)

---

<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:** [June 15, 2023, 3:43pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/10 "2023-06-15T15:43:04Z")

</div>

> [@Michael\_Lindon](#):
>
> Do you use much OO programming and inheritance?

Extensively. Including manipulating and extending jython source code for use in my Ignition add-on modules.

Jython's super() is v2.7, but is implemented in java, not C.

I recommend studying this topic and its linked topics:

> [@\[IGN-5244\]Persist Python Class Object](https://forum.inductiveautomation.com/t/ign-5244-persist-python-class-object/30498):
>
> I am working in Perspective, but this probably applies to other modules as well. I have created user defined classes in the project scripts and I am instantiating them from a view in Perspective. Is there a place I can persist the instance of the object for use between events by the user? Right now I have it serializing to a property on the view, but when I want to work with the object again I have to de-serialize the object in order to work with it again. Having to write custom de-serialize me…

---

<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:** [June 15, 2023, 3:48pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/11 "2023-06-15T15:48:16Z")

</div>

> [@Michael\_Lindon](#):
>
> because I don't think Ignition/Jython dumps script classes from memory for scripts that weren't change.

Ignition constructs new scripting environments from scratch, per affected project, on project save. CPython has nothing comparable.

---

<div class="post-metadata">

**Author:** ![Michael\_Lindon1](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Michael\_Lindon1](https://forum.inductiveautomation.com/u/Michael_Lindon1)\
**Post date:** [July 21, 2023, 3:34pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/12 "2023-07-21T15:34:59Z")

</div>

Heads up, I found a solution to my version of this problem. I had a bunch of inherited and referential classes defined within a single file, when I broke them up across multiple files the error went away.

The source of the error appears to have been two locations, one class was storing references to the other classes in the same file in a class variable. When I moved that class to its own file and imported the other classes into it, the error went away.

The second was a multiple inheritance situation (importing 5 or 6 levels of inheritance from one class to boot). I believe moving it to its own file was the primary fix, but I also changed the classes from using multiple inheritance to a composition pattern.

I believe the cause in both cases is that defining and using classes in the same file can cause issues with load order of the classes, even if you define them in use-case order. This load order issue causes two or more instances of the same class with differing object IDs to be created and referenced depending on when/where the classes are used, which triggers the above error. This would explain why it only sometimes occurs, IE if the inherited/referenced classes are substantiated before the class that references/inherits them is substantiated there is no issue. The solution being, breaking up the file and importing the inherited/reference classes because that guarantees the load order and there is a better chance of not having multiple versions of a class in memory.

Hope this helps.

---

<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:** [July 21, 2023, 3:46pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/13 "2023-07-21T15:46:11Z")

</div>

> [@Michael\_Lindon1](#):
>
> When I moved that class to its own file and imported the other classes into it, the error went away.

Are you talking about files in Ignition's `site-packages` hierarchy? Or are you talking about Ignition's own project scripting library? Because if that latter, and you are importing, you are screwing up. Ignition's project script libraries are not designed to be imported. Ignition cannot track references properly. Use fully qualified names of objects defined in project script libraries anywhere outside themselves.

If you must, for code readability purposes, you can assign a project library to a function local variable and use that within the scope of that function. Do not do this at the top level of a project script.

---

<div class="post-metadata">

**Author:** ![Michael\_Lindon1](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Michael\_Lindon1](https://forum.inductiveautomation.com/u/Michael_Lindon1)\
**Post date:** [July 21, 2023, 4:24pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/14 "2023-07-21T16:24:42Z")

</div>

I am talking about importing other Jython file classes/functions within the Ignition Project library.

IE  
import somewhere.something as something  
or  
from somewhere import something \<- I suggest this one and don't use \*.

I do this extensively and haven't had issues, the only exception being circular referencing. You are correct, Ignition doesn't track references like a dedicated IDE, but it does work.

I am curious what a function local variable looks like to you? I re-use some classes dozens of times in the same script across multiple classes, as well as import multiple classes from the same script. I would be concerned with maintaining a bunch of extra lines of code and creating an additional layer of disconnect between classes and their function.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 21, 2023, 4:51pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/15 "2023-07-21T16:51:41Z")

</div>

> [@Michael\_Lindon1](#):
>
> I am curious what a function local variable looks like to you?

Pretty basic:

```auto
someFunctionName = shared.bigUglyPathThatTakesAMillionKeyStrokes.someFunction

#The instead of using the fully qualified name everytime you need the function you can just use:
someFunctionName()

```

---

<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:** [July 21, 2023, 4:54pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/16 "2023-07-21T16:54:25Z")

</div>

> [@Michael\_Lindon1](#):
>
> import somewhere.something as something

As long as `somewhere.something` is in `site-packages`, that's fine. If it is a project library script, you are setting yourself up for subtle bugs. Ignition project library scripts and packages, while placed in jython's module registry for corner cases, are **not** suitable as the target of import statements.

In a function local is fine. Like so:

```auto
def someFunction():
	something = somewhere.something
	# use something in this function.

```

Don't import from Ignition's project script library. At all.

---

<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:** [July 21, 2023, 4:56pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/17 "2023-07-21T16:56:37Z")

</div>

> [@lrose](#):
>
> Pretty basic

Not like that. That is at module scope. Don't do it. Indented within a function or method is fine.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 21, 2023, 5:03pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/18 "2023-07-21T17:03:28Z")

</div>

Yeah, sorry, since it's local, I assumed that within a function was implied.

---

<div class="post-metadata">

**Author:** ![Michael\_Lindon1](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Michael\_Lindon1](https://forum.inductiveautomation.com/u/Michael_Lindon1)\
**Post date:** [July 21, 2023, 5:08pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/19 "2023-07-21T17:08:40Z")

</div>

> [@pturmel](#):
>
> e. If it is a project library script, you are setting yourself up for subtle bugs. Ignition project library scripts and packages, while placed in jython's module registry for corner cases, are **not** suitable as the target of import statements.

As noted, I use a fairly extensive class based architecture and the only import issue I have found is circular referencing, which I avoid or use referencing similar to what has been described to get around. Can we get more specific with the issues with this method? Is there a specific error or memory issue that is going to eventually creep in? It would be good to know ahead of time.

PS we have veered pretty heavily from the original question, so we might want to move this elsewhere.

---

<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:** [July 21, 2023, 5:13pm UTC](https://forum.inductiveautomation.com/t/gateway-script-error-super-type-obj-obj-must-be-an-instance-or-subtype-of-type/51042/20 "2023-07-21T17:13:16Z")

</div>

It has been a long time since I researched this in depth, but it boils down to some race conditions in jython's module handling combined with Ignition's per-project script environments. The errors, when encountered, are subtle, and tend to be stale code captures.

The only safe approach is to always use fully-qualified paths to resources in project script libraries, with the one exception for time-of-use abbreviations in function or method scope.

Where you can, move your hierarchy to `site-packages`, which does not have this problem.
