scrapy / itemloaders

Library to populate items using XPath and CSS with a convenient API
BSD 3-Clause "New" or "Revised" License
45 stars 16 forks source link

Calling get_output_value causes loader to assign an "empty" value to field #21

Closed tadej-redstone closed 4 years ago

tadej-redstone commented 4 years ago

Description

If a field in an ItemLoader has not been set, calling get_output_value mistakenly assigns an empty object to that item. See the example bellow.

Steps to Reproduce

from scrapy.loader import ItemLoader
from scrapy import Item, Field

class MyItem(Item):
    field = Field()

loader = ItemLoader(MyItem())

Then, simply loading the item correctly produces an empty dict

>>> loader.load_item()
{}

But calling get_output_value before that instantiates the field:

>>> loader.get_output_value("field")
[]

>>> loader.load_item()
{'field': []}