ValueError: dictionary update sequence element #0 has length 1; 2 is required

前端 未结 2 684
北恋
北恋 2021-01-19 02:52

I am returning 5 for my computational field old_default_code, and I am getting the following error:

ValueError: dictionary u

相关标签:
2条回答
  • 2021-01-19 03:13

    The most common way to come across this error is when you have a type casting error, for example,

    MWE to regenerate the error -

    str_var = 'abc'
    str_var = dict(str_var)
    

    Running this gives the error ValueError: dictionary update sequence element #0 has length 1; 2 is required

    Hope this helps.

    0 讨论(0)
  • 2021-01-19 03:20

    @Nebojsa

    The field.function always expect a dictionary to be returned and in your case you are just return an "Integer". The default behaviour of the system is that it expects a dictionary where the key is the "id" of the record and value is the value you want to return.

    For example:

    If you want to return '5' in your case and the record id is 2 then following will be the dictionary {2:5}

    Note:

    While doing calculation whatever ids you have got in your method for all those ids you should return a value in the dictionary, even if no value can be found/calculated then you should return at least false against those ids, but make sure you at least return some value against all the ids that you have got in your function.

    Let me know if you find trouble in this

    Hope this helps..

    0 讨论(0)
提交回复
热议问题