itemloaders icon indicating copy to clipboard operation
itemloaders copied to clipboard

get_output_value behavior differs from load_item with empty data

Open andrewbaxter opened this issue 8 years ago • 1 comments

If an output processor requires a value and a field has no data, doing get_output_value will raise an exception whereas load_item doesn't. I expected get_output_value to return None in this case.

andrewbaxter avatar Jan 27 '17 18:01 andrewbaxter

load_item doesn't even return the field name on fields that it can't parsed(or there is no data), which in my opinion is kinda bad as sometimes it is better to have a default value for fields that are not found.

The only 2 times get_output_value raises an error are :

  • There is some kind of Exception on the output_processor for the specific field name
  • The field name does not contain inside self._values

I use this personal function to fill in missing a default value for missing field names after an item has been loaded using the load_item method.


def default_missing_keys(item, default_value='', except_keys=[]):

    missing_keys = list(set(item.fields.keys()) - set(item.keys()))
    for missing_key in missing_keys:
        if except_keys:
            if missing_key not in except_keys:
                item[missing_key] = default_value
        else:
            item[missing_key] = default_value

IAlwaysBeCoding avatar Jan 28 '17 02:01 IAlwaysBeCoding