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

Unexpected behaviour while adding scrapy.Item sub class as a value to itemloader. #28

Closed
HassanQamar07 opened this issue Sep 15, 2020 · 0 comments · Fixed by #29
Closed
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@HassanQamar07
Copy link

HassanQamar07 commented Sep 15, 2020

Sample code

import scrapy
from itemloaders import ItemLoader
from itemloaders.processors import Identity


class TestItem1(scrapy.Item):
    list_of_test_items = scrapy.Field()


class TestItem2(scrapy.Item):
    count = scrapy.Field()
    price = scrapy.Field()


class TestItemLoader(ItemLoader):
    default_item_class = TestItem1

    list_of_test_items_in = Identity()
    list_of_test_items_out = Identity()


il = TestItemLoader()
il.add_value('list_of_test_items', TestItem2(count=1, price=50))
print(il.load_item())

Expected output

{'list_of_test_items': [{'count': 1, 'price': 50}]}

Actual output

{'list_of_test_items': ['count', 'price']}

This is because the _BaseItem is removed from _ITERABLE_SINGLE_VALUES https://github.com/scrapy/itemloaders/blob/master/itemloaders/utils.py#L9

In scrapy _BaseItem is included in _ITERABLE_SINGLE_VALUES https://github.com/scrapy/scrapy/blob/2.2/scrapy/utils/misc.py#L20

@Gallaecio Gallaecio added bug Something isn't working good first issue Good for newcomers labels Sep 16, 2020
@Gallaecio Gallaecio self-assigned this Oct 25, 2020
@wRAR wRAR closed this as completed in #29 Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants