Strange error: "object has no attribute 'addDays'"

I’m seeing this error in my logs:

image

The line in question is:

image

I know that functions invoked via system.util.invokeAsynchrounous() don’t have access to system.perspective but it’s as if there’s a different version of system.date that gets invoked in that context…

Can you show your full script, where/how your defining the function you’re calling async? IIRC this may be the legacy scoping thing that’s brought up as a reason to define all your functions in script modules directly. Is this all being done on an event (like a button push -you’re defining the fucntion you want to call async on the event?) Give more context please

An expression binding invokes the library function getMachineAndPartDayData:

runScript('GUI.Data.DayTotals.getMachineAndPartDayData', 30000, {view.custom.queryStartDate}, {view.custom.queryEndDate}, {view.params.machine}, {view.params.partType})

GUI.Data.DayTotals:

def getMachineAndPartDayData(startDate, endDate, machine, partType):
	...
	activeShifts = Shifts.getAllActiveShifts(startDate) 
	...

Shifts:

def getAllActiveShifts(date=None, secondary=False):
	...
	for i in range(7):
		shifts = getActiveShifts(system.date.addDays(date, i), secondary)
	...

Edit: Having layed it out, I’m now wondering how invokeAsynchronous fits into it. There might be another path to it I’m overlooking…

No, that’s the only reference to getMachineAndPartDayData I see–it must be the 30-second polling that invokes it asynchronously.

Wait are you invoking async somehere or no? I don’t see it so I don’t think that’s an issue.

But looking at this -

runScript('GUI.Data.DayTotals.getMachineAndPartDayData', 30000, {view.custom.queryStartDate}, {view.custom.queryEndDate}, {view.params.machine}, {view.params.partType})

Seems like you are just getting user input params, and waiting 30 seconds to re-calculate? I’d either do it on prop change, or more likely on a button press and avoid the runScript all together. Have the person pick there params and then click submit and then you run your script directly on button press. Feels like bad UI to set it and then potentially have to wait 30 seconds.

It’s just refreshing the data every 30 seconds. That’s a poll rate, not an initial delay.

Does the machine and part data actually change within 30 seconds assuming all params are the same? If so then fair enough way to handle it, but if not I’d do it on an event.

Do you have your global scripting project set? Expression and runScript problem - #9 by dkhayes117

Though I suppose it shouldn’t matter for system.date since you are getting that far. Hm idk. Somewhere it’s losing context.

You could try putting a import system at the top of your getAllActiveShifts function would resolve it but it’s icky to be importing system packages but you may just have to because it’s being called async on the gateway scope. Here’s an IA employee doing exactly that Changing Perspective Project from Session - #2 by cmallonee

I believe I ran into a vaguely similar issue on a gateway tag change script, and putting an import into my project library script solved it (like @bkarabinchak.psi is suggesting). Not sure if the same quirk is happening here.

I’ve always had the global scripting project set, though I know I’ve seen errors in the past stating "ignition perspective scripting project is not set" which was confounding.

Did you try the import system like in the second link I mentioned? I think its the fact it’s running in async on the gateway that makes it necessary.

Make sure you do not have a variable named system that is overriding the handle for system functions.

1 Like

Yes, but that error came out of nowhere and I couldn’t get it to show up again before doing so, so it’s hard to say if it will have an effect.

That would make sense, but the script was written entirely by me, and I know better than to do that.

Are you saying it used to work but now does not?

No, I have no indication outside that one time error that the code was not working, and after loading the view that invokes that code several times, I could not get another error to show up. That’s why it’s hard to say if adding the import will fix something, when I’m not even sure that it’s broken…

Is your data coming through on your view? Gateway logs often start hiding repeat errors unless you set it to debug for that logger.

I bet this is just an import race, that should have been fixed in 8.3.

2 Likes

Yes, the view shows the data fine.

I only noticed the error because I’ve been combing through the logs looking for possible reasons that the gateway has been flaky the last couple weeks. A couple times a day it would suddenly start timing out when trying to read tags, occasionally rebooting itself in the process. We were thinking maybe a faulty network switch, but we also had two IPs configured for the same NIC, and since switching them to use separate ones, we haven’t seen that problem…