# Error when passing a List to project script

**URL:** <https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [April 27, 2022, 3:13pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931 "2022-04-27T15:13:16Z")\
**Posts on this page:** 9\
**Page:** 1

<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:** [April 27, 2022, 3:13pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/1 "2022-04-27T15:13:16Z")

</div>

This one has me a little stumped. I’m writing a project script function and I want to send a list as one of the parameters. However, I get a CastException error.

I’m currently executing this in the script console. Ignition Version is 8.1.14

Relevent Code

```auto
print type(paths)
print Orestes.Daily_DT.getDailyDT_CountsData(paths,aliases,startTime1)

```

Console Output

```auto
<type 'list'>
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 42, in <module>
  File "<module:Orestes.Daily_DT>", line 27, in getDailyDT_CountsData
	at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1493)

	at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:130)

	at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:104)

	at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:40)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.queryTagCalculations(AbstractTagUtilities.java:681)

	at jdk.internal.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value 'set(['HalfSpdWhse4', 'NoTomatoes', 'Cooker', 'NoCans', 'Seamer', 'Depal', 'CleanMode', 'HalfSpdLowTom', 'NoMedia'])' into type: class org.python.core.PySequence

```

For completeness the code at Line 27 is this:

```auto
daysData = system.tag.queryTagCalculations(paths,['Range'],startTime1,endTime1,aliases = aliases)

```

What could be happening that causes this List to be converted to a Set?

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [April 27, 2022, 3:15pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/2 "2022-04-27T15:15:21Z")

</div>

Show the code that creates paths.

---

<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:** [April 27, 2022, 3:18pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/3 "2022-04-27T15:18:30Z")

</div>

Code that is creating paths:

```auto
paths = []
aliases = []

for k,v in tpml.iteritems():
	paths.append(v)
	aliases.append(k)

```

tpml is a Dictionary where the Key is the alias I want to use for the tag path which is the Value.

---

<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:** [April 27, 2022, 3:23pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/4 "2022-04-27T15:23:22Z")

</div>

Can you post all of `Orestes.Daily_DT.getDailyDT_CountsData`?

---

<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:** [April 27, 2022, 3:26pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/5 "2022-04-27T15:26:57Z")

</div>

```auto
def getDailyDT_CountsData(paths,aliases,day):
	startTime1 = system.date.setTime(day,6,30,0)
	endTime1 = system.date.setTime(day,18,30,0)
	endTime2 = system.date.addDays(startTime1,1)
	
	daysData = system.tag.queryTagCalculations(paths,['Range'],startTime1,endTime1,aliases = aliases)
	nightsData = system.tag.queryTagCalculations(paths,['Range'],endTime1,endTime2,aliases = aliases)
	
	headers = ['DT-Event','Minutes-Days','Minutes-Nights','Counts-Days','Counts-Nights']
	aliases = {alias.split('_')[0] for alias in aliases if alias not in ('CansTarget','CansAct')}
	
	rows = [[alias,days[0][alias],nights[0][alias],days[1][alias],nights[1][alias]] for alias in aliases]
	
	return system.dataset.toDataSet(headers,rows)

```

Line 27 is the assignment to `daysData`

---

<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:** [April 27, 2022, 3:30pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/6 "2022-04-27T15:30:54Z")

</div>

Where are you defining `aliases` before calling your project library script?

Your comprehension in the project lib is using a set (which isn’t going to respect ordering, probably not what you want) - are you using the same pattern when invoking the script?

---

<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:** [April 27, 2022, 3:36pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/7 "2022-04-27T15:36:34Z")

</div>

aliases is defined in the same for loop where paths is defined.

```auto
paths = []
aliases = []

for k,v in tpml.iteritems():
	paths.append(v)
	aliases.append(k)

```

I will change that comprehension, I think the set was left over from a previous iteration, either way, the error occurs prior to that line in the script. I’m really only needing to remove the CansTarget and CansAct from the list, and there is a better way to accomplish that anyway.

---

<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:** [April 27, 2022, 3:41pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/8 "2022-04-27T15:41:14Z")

</div>

In reality there are other helper functions which do this as well, they are defined in the same script library.

```auto
def getDailyDT_TagPathsList(lineNumber):
	baseTagPath = 'baseTagPath/L{}'.format(lineNumber)
	return [str(result['fullPath']) for result in system.tag.browse(baseTagPath + 'DT').results]

def getDailyDT_PathsDict(lineNumber):
	baseTagPath = '[baseTagPath/L{}/'.format(lineNumber)
	dtQueryPaths = ['Yearly_Minutes_Current','Yearly_Counts_Current']

	tpl = getDailyDT_TagPathsList(lineNumber)
	tpml = {path.split('/',-1)[-1] + '_' + qPath.split('_')[1]:path + '/' + qPath for qPath in dtQueryPaths for path in tpl}

	tpml['CansAct'] = baseTagPath + '/EFF/CapperCounts_Yearly'
	tpml['CansTarget'] = baseTagPath + '/EFF/TargetCansYearly'

	paths, aliases = [],[]
	for k,v in tpml.iteritems():
		paths.append(v)
		aliases.append(k)

	return {'paths':paths,'aliases':aliases}

```

In practice` getDailyDT_PathsDict()` is used in a binding on a custom property, and then the ‘paths’ array and ‘aliases’ array are used in the call to `getDailyDT_CountsData`

`getDailyDT_CountsData` is intended to return a dataset to a table component on a perspective view.

---

<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:** [April 27, 2022, 3:44pm UTC](https://forum.inductiveautomation.com/t/error-when-passing-a-list-to-project-script/58931/9 "2022-04-27T15:44:26Z")

</div>

`daysData = system.tag.queryTagCalculations(paths,['Range'],startTime1,endTime1,aliases = list(aliases))`

What if you change line 27 like this? I wonder if the comprehension that’s re-using the same variable is leaking backwards, somehow? It’s hard to say without seeing everything in order to track the data flow (put it on the pile of issues that would be easy to solve with a debugger 😭).
