Jython: NameError after upgrading to 2.3 snapshots

  • Platform information: RPi3
    • OS: Raspbian Jessie
    • Java Runtime Environment: Java™ SE Runtime Environment (build 1.8.0_131-b11)
    • openHAB version: 2.3.0-SNAPSHOT (#1262)

I upgraded today from 2.2 stable to the above mentioned snapshot build. Since the upgrade I see errors in the log about the global name DateTime not being defined:

2018-04-23 16:17:10.796 [ERROR] [pse.smarthome.automation.rules.rolladenBeschattung] - Traceback (most recent call last):
  File "/etc/openhab2/lib/python/openhab/log.py", line 14, in wrapper
    return fn(*args, **kwargs)
  File "<script>", line 381, in execute
NameError: global name 'DateTime' is not defined

The lines in the jython code that errors is the following:

        MinDiff5Min = float("{0:.2f}".format(float(str(pe.minimumSince(ir.getItem('tDiffSN'),DateTime.now().minusMinutes(10)).state))))

I have the following (openhab-related) imports in my jython script:

from openhab.actions import Pushover, Mail
from openhab.log import logging
from openhab.testing import run_test
from openhab.triggers import ItemStateChangeTrigger
from openhab.triggers import ItemStateUpdateTrigger
from openhab.triggers import ItemCommandTrigger   
from openhab.triggers import CronTrigger
from openhab.triggers import ChannelEventTrigger
from org.eclipse.smarthome.model.persistence.extensions import PersistenceExtensions as pe
from threading import Timer
from openhab.rules import rule, addRule

Have there been any changes between 2.2 stable and 2.3 that would produce such errors? Any more Imports that I need to add to make the rule work as it used to do before the upgrade?

EDIT: This does not seem to be a bundle start issue since it persists even when the jython script is being touched and reloaded by openhab after that.

Thanks for any help!

The solution for my problem seems quite easy AFTER I found it.

It seemd DateTime has to be imported when the script runs on a build:

import org.joda.time.DateTime as DateTime

This import fixes the error for me.

This solution worked for me too.