Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
5723 Vistas

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
Descartar
Autor

I tried if condition, but still error.

Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar