The judgement is not correct, sometime if the key is exist but value is null, a new item will be created. I suggest the next codes:
def flatten_id(item, target): if target in item: if item[target] is not None: item[target + '_id'] = item.pop(target, {}).pop('id', None) return else: item.pop(target, {}) item[target + '_id'] = None
The judgement is not correct, sometime if the key is exist but value is null, a new item will be created. I suggest the next codes:
def flatten_id(item, target): if target in item: if item[target] is not None: item[target + '_id'] = item.pop(target, {}).pop('id', None) return else: item.pop(target, {}) item[target + '_id'] = None