# Unexpected behaviour from isinstance(), issubclass(), and type comparison

**URL:** <https://forum.inductiveautomation.com/t/unexpected-behaviour-from-isinstance-issubclass-and-type-comparison/99382>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [December 3, 2024, 7:16pm UTC](https://forum.inductiveautomation.com/t/unexpected-behaviour-from-isinstance-issubclass-and-type-comparison/99382 "2024-12-03T19:16:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathon\_Platt](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@Jonathon\_Platt](https://forum.inductiveautomation.com/u/Jonathon_Platt)\
**Post date:** [December 3, 2024, 7:16pm UTC](https://forum.inductiveautomation.com/t/unexpected-behaviour-from-isinstance-issubclass-and-type-comparison/99382/1 "2024-12-03T19:16:11Z")

</div>

Hello

I'm having an issue with asserting that an instance of my custom `Report` class is actually an instance of the class. I have a module where I declare a `Report` and `ReportDAO` class. In the `ReportDAO` class I have an `update` function which takes a `Report` instance and modifies it, but first I want to assert that the passed report is the correct object type.

simplified:

```python
class Report(object):
    uuid = None

    def __init__ (self, uuid):
        self.uuid = uuid or str(uuid_module.uuid1())

```

```python
class ReportDAO(object):
    """
    Data access for Report objects
    """

    def update(self, report):
        """
        Update a single report record
        """
        assert_is_report(report)
        # updates go here

```

The `assert_is_report` just does an `issubclass` check under the hood but it is failing when passing a report object. I added a bunch of logging to the update function and get the following log results:

```python
    def update(self, report):
        """
        Update a single report record
        """
        log.info("report. __class__ : {}".format(report. __class__ ))
        log.info("type(report): {}".format(type(report)))
        log.info("Report: {}".format(Report))
        log.info(
            "issubclass(type(report), Report): {}".format(
                issubclass(type(report), Report)
            )
        )
        log.info("isinstance(report,Report): {}".format(isinstance(report, Report)))
        log.info("type(report) is Report: {}".format(type(report) is Report))

        new_report = Report(None, None, None)
        log.info("new_report. __class__ : {}".format(new_report. __class__ ))
        log.info("type(new_report): {}".format(type(new_report)))
        log.info("Report: {}".format(Report))
        log.info(
            "issubclass(type(new_report), Report): {}".format(
                issubclass(type(new_report), Report)
            )
        )
        log.info(
            "isinstance(new_report,Report): {}".format(isinstance(new_report, Report))
        )
        log.info("type(new_report) is Report: {}".format(type(new_report) is Report))

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/d/0dc442d823ac4a78fd5ecb765899f2929e93b664.png)

why is my report instance that is passed to the update function not being recognised as an instance of `Report` class?

for additional context, the report instance has been saved to and then retrieved from a list at `system.util.getGlobals["reports"]`, and the saving and retrieving is being done by two different projects, that both import the `Report` and `ReportDAO` classes directly

---

<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:** [December 3, 2024, 8:37pm UTC](https://forum.inductiveautomation.com/t/unexpected-behaviour-from-isinstance-issubclass-and-type-comparison/99382/2 "2024-12-03T20:37:52Z")

</div>

Have you seen this topic?

> [@\[IGN-6503\]Project Library Script Initialization Races](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636):
>
> Are you annoyed by pseudo-random breakage in Ignition project library scripting? Odd top-level constants being garbled, or operations in the top level that have side effects running twice? Or more? Not happening much, but always around project edits, and sometimes even on gateway restart? Yeah, me too. frowning_face Poking around under the hood back in the spring, for a module development task, I ran across some problematic IA bytecode and pinged some people. But it went nowhere, as I co…

---

<div class="post-metadata">

**Author:** ![Jonathon\_Platt](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@Jonathon\_Platt](https://forum.inductiveautomation.com/u/Jonathon_Platt)\
**Post date:** [December 4, 2024, 5:11pm UTC](https://forum.inductiveautomation.com/t/unexpected-behaviour-from-isinstance-issubclass-and-type-comparison/99382/3 "2024-12-04T17:11:51Z")

</div>

Yes thanks I came across that when I was looking to see if anyone else had the same issue as me in the forums. If I understand correctly the issue may be because the module that contains my `Report` and `ReportDAO` classes is being imported / initialized by ignition multiple times? And so I have multiple versions of the `Report` class floating around?

And the solution you have presented aims to prevent ignition from loading that particular script more than once?

---

<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:** [December 4, 2024, 5:58pm UTC](https://forum.inductiveautomation.com/t/unexpected-behaviour-from-isinstance-issubclass-and-type-comparison/99382/4 "2024-12-04T17:58:30Z")

</div>

Yes, and yes. The workaround is not a complete bugfix, as it doesn't eliminate cross-script AB-BA deadlock possibilities.
