Atrribute error on Callback function

Hi,

From a table I would like to make a selection with to optionfields by means of a callback function. However I get an attribute error when I try to use the output of the first optionfield in the second optionfield as a filter condition.

The error is;

Traceback (most recent call last):
File “viktor/parametrization.pyx”, line 2336, in viktor.parametrization._SelectField._handle_options_constraint
File “/usr/src/app/app/calculation/parametrization.py”, line 17, in get_equipment_options
df_flocs_filter = df_flocs[‘FLOC’][(df_flocs.Type == str(params.picked_type))]
File “/usr/src/packages/munch/init.py”, line 108, in getattr
raise AttributeError(k)
AttributeError: picked_type

This is my code;

def get_type_options(params, **kwargs):
dict_types = params.types.values()
dict_values = params.failures.values()
type_options = list(dict_types)
return type_options

def get_equipment_options(params, **kwargs):
df_flocs = pd.DataFrame.from_dict(params.flocs, orient=‘index’,columns=[‘FLOC’])
df_flocs[‘Type’] = pd.DataFrame.from_dict(params.types, orient=‘index’,columns=[‘Type’])
df_flocs_filter = df_flocs[‘FLOC’][(df_flocs.Type == str(params.picked_type))]
dict_flocs = df_flocs_filter.to_dict()
floc_options = list(dict_flocs.values())
return floc_options

class CalculationParametrization(Parametrization):

general = Tab('General')
general.object = Section('Object')
general.object.picked_type = OptionField('Pick type', options=get_type_options)
general.equipment = Section('Equipment')
general.equipment.eq = MultiSelectField('Pick equipment', options=get_equipment_options)


downloads = Tab('Downloads')    
downloads.calculation_sheet = Section('Updated PoFs')    
downloads.calculation_sheet.set_params = SetParamsButton('Update', method='set_params')
downloads.calculation_sheet.orders = HiddenField("orders", name='orders')
downloads.calculation_sheet.types = HiddenField("types", name='types')
downloads.calculation_sheet.flocs = HiddenField("flocs", name='flocs')
downloads.calculation_sheet.fail_rates = HiddenField("rates", name='fail_rates')
downloads.calculation_sheet.failures = HiddenField("failures", name='failures')

It looks like params.picked_type doesn’t exist in your parametrization. You could create the short-hand alias by adding OptionField(..., name='picked_type'), or replace

df_flocs_filter = df_flocs[‘FLOC’][(df_flocs.Type == str(params.picked_type))]

with

df_flocs_filter = df_flocs[‘FLOC’][(df_flocs.Type == str(params.general.object.picked_type))]

That easy! Adding the ‘name’ did the trick.

Thanks!