Dataiku 12.4 API breaking change

Turribeach
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,161 Neuron

For anyone out there moving to Dataiku 12.4 be aware that there is a breaking change in Dataiku 12.4 API. Dataiku has decided to add add timezone to their date/time objects returned by the API so if you do any sort of date/time calculations with the API date/time fields you might get an error.

The following sample code:

import dataikuapi
import datetime

# Create a Dataiku client
dataiku_url = 'url'
dataiku_api_key = 'key'

dataiku_client = dataikuapi.DSSClient(dataiku_url, dataiku_api_key)
dataiku_client._session.verify = False

project = dataiku_client.get_project('project')
scenario = project.get_scenario('scenario')
 
last_run = scenario.get_last_finished_run()
run_since_delta = datetime.datetime.now() - last_run.end_time

Fails with this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 run_since_delta = datetime.datetime.now() - last_run.end_time

TypeError: can't subtract offset-naive and offset-aware datetimes

Best Answer

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,161 Neuron
    edited July 17 Answer ✓

    Forgot to post posible solutions. If you are outside Dataiku one option is to downgrade the Dataiku API package:

    pip install dataiku-api-client==12.3.2

    Another option is to strip out the time zone component from the date/time object:

    run_since_delta = datetime.datetime.now() - last_run.end_time.replace(tzinfo=None)

    And the cleanest solution is to modify your code to also use time zone:

    import pytz
    run_since_delta = datetime.datetime.now().replace(tzinfo=pytz.UTC) - last_run.end_time

    But this will probably require further changes in your code.

Setup Info
    Tags
      Help me…