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

input_processor called only once #36

Open
dolohow opened this issue Oct 5, 2016 · 3 comments
Open

input_processor called only once #36

dolohow opened this issue Oct 5, 2016 · 3 comments

Comments

@dolohow
Copy link

dolohow commented Oct 5, 2016

Hi guys,

I am using input_processor on custom ItemLoader along one inside Field declaration that belongs to Item which is being used by ItemLoader. The problem is that only ItemLoader fires up the input_processor. Is it a desired behavior?

Related code:

class ProductsItem(scrapy.Item):
    # input_loader is not called
    currency = scrapy.Field(input_processor=MapCompose(utils.get_unified_currency_name))

class CustomProductLoader(ItemLoader):
    default_output_processor = TakeFirst()
    # input_loader works fine here
    currency_in = MapCompose(lambda x: x[0])

class MySpider(scrapy.Spider):
    # ....
    def parse(self, response):
        for product in response.css('bla bla'):
            loader = CustomProductLoader(ProductsItem(), product, response=response)
            loader.add_css('currency', 'bla bla')
@redapple
Copy link
Contributor

redapple commented Oct 10, 2016

Hi @dolohow , I'm having trouble understanding the behavior you are describing.
Could you show the behavior in a scrapy or Python shell session, with item loader calls and comments on what you expected vs. what you see as outputs?

@dolohow
Copy link
Author

dolohow commented Oct 12, 2016

@redapple I work around this by creating a custom pipeline for validation.

get_unified_currency_name is not called on a scrapy.Field currency. Is like one input_processor overrides the other one. Maybe this is a desired behaviour, but I was thinking that it could execute both of them:

# first one that is called
currency_in = MapCompose(lambda x: x[0])

# second one that is not called
currency = scrapy.Field(input_processor=MapCompose(utils.get_unified_currency_name))

but if you remove the currency_in = MapCompose(lambda x: x[0]), utils.get_unified_currency_name) will be called.

@Gallaecio Gallaecio transferred this issue from scrapy/scrapy Oct 30, 2020
@Gallaecio
Copy link
Member

I think it is indeed intended behavior, and I’m personally not sure it would be wise to implement a way to change that behavior.

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

3 participants