# \[IGN-5604\] scoping weirdness after call to system.report functions

**URL:** <https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022>\
**Category:** Ignition\
**Created:** [October 26, 2023, 11:49am UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022 "2023-10-26T11:49:01Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 26, 2023, 11:49am UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/1 "2023-10-26T11:49:01Z")

</div>

Hello folks,

Noticed something quite strange today.  
I have a script that calls `system.db.runNamedQuery` a few times, and one of them would error out with this error:

> `java.lang.IllegalArgumentException: Project name required for script execution: the Gateway Scripting Project is not set.`

Using the gateway scope version, with the project name, fixed it. But I couldn't wrap my head around this, as other calls worked just fine.  
So I talked about it with coworkers, and turns one of them had the exact same issue just yesterday.  
The one thing in common that's just too big to be a coincidence is that we both had a call to a report function right before the named query - `executeReport` for him, `executeAndDistribute` for me.

So I tried moving the named query to before the report function call and, lo and behold, it works just fine with the project scope syntax.

Version is 8.1.17 (at least for me, don't know about my coworkers'. I should ask).  
Is this something you heard before ? Maybe it's been fixed since ? I couldn't find anything with a quick search on the forums.  
Is it bug report o'clock ?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 26, 2023, 11:52am UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/2 "2023-10-26T11:52:37Z")

</div>

What do you have set here? Under config-\>Gateway settings.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/3/23eecf7614dd49b45d2f894949778c4b46976954.png)

And can you post the script, the before and after where you moved the lines?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 26, 2023, 12:04pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/3 "2023-10-26T12:04:02Z")

</div>

I don't think that's relevant here: I understand what the gateway scripting project is what it's used for, but the point here is that it's not needed for the calls to `runNamedQuery` that happen before the call to `executeReport`, but it's needed after them.  
Maybe setting the scripting project would fix it, but there's still something funky going on.

The script looks like this:

```python
system.db.runNamedQuery("query_path")
function_that_runs_report_function()
system.db.runNamedQuery("other_query_path")

```

First query works fine, second does not, unless I use the gateway scope syntax.  
If I do this instead:

```python
system.db.runNamedQuery("query_path")
system.db.runNamedQuery("other_query_path")
function_that_runs_report_function()

```

the problem goes away.

That script is in a message handler, the reporting function is in the project library.

I'll talk with the coworker in the afternoon, gather some data, then maybe file a bug report.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 26, 2023, 12:13pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/4 "2023-10-26T12:13:27Z")

</div>

What's going on in here - `function_that_runs_report_function()` just getting params for `executeReport`/`executeAndDistribute`?

Please update this post when you get some answer from IA, I have run into some similar weirdness where I unexpectedly need a project name for a NQ.

---

<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:** [October 26, 2023, 12:16pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/5 "2023-10-26T12:16:58Z")

</div>

> [@pascal.fragnoud](#):
>
> Is it bug report o'clock ?

Sounds like it to me. Reporting blowing up the project thread local.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 26, 2023, 12:35pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/6 "2023-10-26T12:35:55Z")

</div>

I tried recreating it in 8.1.26 but it works correctly so perhaps this is a bug they were aware of and fixed? My message handling script.

```auto
def handleMessage(payload):
	logger = system.util.getLogger("TEST NQ")
	logger.info("Running NQ")
	ds = system.db.runNamedQuery("test",{"idx":1})
	logger.info("Got result %s"%(str(ds.getValueAt(0,0))))
	test.makeReport()
	logger.info("Running NQ 2")
	ds = system.db.runNamedQuery("test2",{"idx":1})
	logger.info("Got result 2 %s"%(str(ds.getValueAt(0,0))))

```

and my makeReport function is doing similar to yours I assume

```auto
def makeReport():
	logger = system.util.getLogger("R Logger")
	logger.info("Making report")
	data = system.report.executeReport("test_Report")
	logger.info("Made report")

```

This works without throwing me any error and I get what I expect.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 26, 2023, 12:42pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/7 "2023-10-26T12:42:08Z")

</div>

> [@pascal.fragnoud](#):
>
> Is it bug report o'clock ?

If it still happens after upgrading to latest, yes.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 26, 2023, 12:43pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/8 "2023-10-26T12:43:14Z")

</div>

I just talked to my coworker, and his project is on 8.1.30, so there's something else.  
AND his scripting project was configured.

One thing though: I first tried reproducing the issue with a simple named query that was just a `select 1`, and no issue was raised.

Both my coworker and I are using an update named query when the issue happens. Maybe that's also a factor.

edit: Nope, tried replacing with a `select 1` named query and got the same error.  
Even after setting the scripting project, it says "the Gateway Scripting Project is not set."

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 26, 2023, 12:48pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/9 "2023-10-26T12:48:15Z")

</div>

I'm pretty sure this is a bug... think I found it. I'll write up a ticket.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 26, 2023, 1:08pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/10 "2023-10-26T13:08:03Z")

</div>

In the meantime, can I reliably use this ?

```auto
system.db.runNamedQuery(
	path="query_path",
	parameters=params,
	project="project_name"
)

```

It works in both scopes, but I'm wondering if it's a reliable workaround.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 26, 2023, 1:10pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/11 "2023-10-26T13:10:14Z")

</div>

Yes, the report scripting call is clearing out some thread local state about what the default project is, which makes the subsequent `runNamedQuery` without it specified fail.

---

<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:** [October 26, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/12 "2023-10-26T13:48:14Z")

</div>

Is there a range of affected versions? Or has this been there forever?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 26, 2023, 1:57pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/13 "2023-10-26T13:57:45Z")

</div>

FWIW I was wholly unable to recreate the issue in 8.1.26, I changed my SELECT to UPDATES as @pascal.fragnoud mentioned, used a combination of both, in different orders. Maybe I am doing something different in my report script, since I am only doing `executeReport` instead of `exceuteAndDistribute`. But I have had no luck recreating it in this version.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 26, 2023, 2:52pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/14 "2023-10-26T14:52:32Z")

</div>

Possibly since 8.0.11, but that's just the call that clears the thread local state, without investigating all the other pieces to see if it was actually affected starting that version.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 26, 2023, 3:46pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/15 "2023-10-26T15:46:53Z")

</div>

I'm pretty sure this has basically always been a thing; there's other manifestations of it reported 2 years ago.

One of the "under the hood" changes I'm planning to make in 8.3.0, when I have a window to break APIs, is a better/less fragile method to "stack" contexts - i.e. a report's execution setup/teardown just should not be able to "leak" to the tag event script, async thread, whatever that called it.

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [June 6, 2025, 5:51pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/16 "2025-06-06T17:51:19Z")

</div>

Ran into this exact bug in 8.1.47.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 6, 2025, 6:46pm UTC](https://forum.inductiveautomation.com/t/ign-5604-scoping-weirdness-after-call-to-system-report-functions/81022/17 "2025-06-06T18:46:03Z")

</div>

Yes, this bug is fixed in 8.3 but cannot be fixed in 8.1.
