Se rendre au contenu
Menu
Cette question a été signalée
3 Réponses
5748 Vues

def map_field2write(self, field2write):
        res = {}
        field_names = self._get_fieldnames()
        for fn in field2write.keys():
            if fn not in field_names:
               continue
            else:
               res[field_names[fn]] = field2write[fn]
        return res


what is the error?



Avatar
Ignorer
Auteur

I tried if condition, but still error.

Meilleure réponse

Error clearly says field2write 'bool' object has no attribute 'keys'
To avoid check is fiel2write contain value and type dict then other line code execute

Example:

Check

if field2write:

    for fn in field2write.keys():

Avatar
Ignorer
Meilleure réponse

Hi,

You can try update the method as below

def map_field2write(self, field2write):
res = {}
if not field2write:
return res
field_names = self._get_fieldnames()
for fn in field2write.keys():
if fn not in field_names:
continue
else:
res[field_names[fn]] = field2write[fn]

return res

Regards

Avatar
Ignorer