BUG: dataiku.get_custom_variables() returns Python string instead of dict at lower levels
![info-rchitect](https://us.v-cdn.net/6038231/uploads/lithium_attachments/n9089iA7C08C68990A5113.png)
info-rchitect
Registered Posts: 172 ✭✭✭✭✭✭
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 Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 118 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)
Answers
-
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