BUG: dataiku.get_custom_variables() returns Python string instead of dict at lower levels

info-rchitect
info-rchitect Registered Posts: 179 ✭✭✭✭✭✭
edited July 16 in Using Dataiku

Hi,

I tried `get_custom_variables` function and found it does not return the proper Python classes at the lower levels of the `dict`.

REPRODUCE:

Create 'bug' variable:

import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu

project_handle = dataiku.api_client().get_project(dataiku.default_project_key())

vars = project_handle.get_variables()['standard']

# This does not return JSON objects after the top-level dict
custom_vars = dataiku.get_custom_variables()

print(f"should be a dict, type actually is {type(custom_vars['bug'])}")
print(f"should be a dict, and is a {type(vars['bug'])}")

exit()
[08:50:29] [INFO] [dku.utils]  - should be a dict, type actually is <class 'str'>
[08:50:29] [INFO] [dku.utils]  - should be a dict, and is a <class 'dict'>  


Here is the log output that shows `get_custom_variables` returns a str instead of a dict:


{
  "bug": {
    "dict1": {
      "a": 1,
      "b": 2
    }
  }
}

Operating system used: Windows 10

Tagged:

Best Answer

  • Miguel Angel
    Miguel Angel Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 118 Dataiker
    edited July 17 Answer ✓

    Hi,

    As you have proved, the method 'get_custom_variables' will by default return the variable values as strings in the returned dictionary.

    If you want the values to be typed, call the function with the following argument:

    custom_vars = dataiku.get_custom_variables(typed=True)

    Capture.png

Answers

Setup Info
    Tags
      Help me…