Survey banner
Share your feedback on the Dataiku documentation with this 5 min survey. Thanks! TAKE THE SURVEY

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

Solved!
info-rchitect
Level 6
BUG: dataiku.get_custom_variables() returns Python string instead of dict at lower levels

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:

 

{
  "bug": {
    "dict1": {
      "a": 1,
      "b": 2
    }
  }
}
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()

 

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


[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'>  

Operating system used: Windows 10

 

0 Kudos
1 Solution
MiguelangelC
Dataiker

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

 

View solution in original post

2 Replies
MiguelangelC
Dataiker

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

 

info-rchitect
Level 6
Author

@MiguelangelC 

 

Thanks for the solution.  Does it make sense to change the default to `typed=True`?  This would match the behavior of the other API to retrieve project variables.

 

thx

0 Kudos

Labels

?
Labels (1)
A banner prompting to get Dataiku