Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_output_value behavior differs from load_item with empty data #45

Open
andrewbaxter opened this issue Jan 27, 2017 · 1 comment
Open

Comments

@andrewbaxter
Copy link

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.

@IAlwaysBeCoding
Copy link

IAlwaysBeCoding commented Jan 28, 2017

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

@Gallaecio Gallaecio transferred this issue from scrapy/scrapy Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants