Skip to Content
Menu
This question has been flagged
3 Replies
5236 Views

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
Discard
Author

I tried if condition, but still error.

Best Answer

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
Discard
Best Answer

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
Discard