Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Added on April 18, 2023 12:57PM
Likes: 0
Replies: 2
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
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)
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