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

Assertion error after nested #87

Closed
tonal opened this issue Jun 1, 2024 · 5 comments · Fixed by #88
Closed

Assertion error after nested #87

tonal opened this issue Jun 1, 2024 · 5 comments · Fixed by #88

Comments

@tonal
Copy link

tonal commented Jun 1, 2024

If xpath in nested_xpath not exists
Code

      info = loader.nested_xpath('.//div[@class="product-card__more-info"]')
      info.add_xpath('artikul', 'p[1][span/text() = "Код товара:"]/text()')

Assertion in _get_xpathvalues:

assert self.selector
@wRAR
Copy link
Member

wRAR commented Jun 1, 2024

Can you please provide a minimal reproducible example?

@VMRuiz
Copy link
Contributor

VMRuiz commented Jun 3, 2024

I was able to reproduce it with:

from parsel import Selector
from itemloaders import ItemLoader
loader = ItemLoader(selector=Selector('<body></body>'))
nl1 = loader.nested_xpath('//missing-tag')
nl1.add_xpath('foo', './/p/text()')

@VMRuiz
Copy link
Contributor

VMRuiz commented Jun 3, 2024

I'm not sure what's the expected behavior in this case:

  1. Raise an error on nested_xpath
  2. nested_xpath returns None
  3. nested_xpath returns itself

I would go with 2 and let the developer check for empty values on their side.

@wRAR
Copy link
Member

wRAR commented Jun 3, 2024

Asserts are just incorrect, self.selector in this case is an empty SelectorList.

@wRAR
Copy link
Member

wRAR commented Jun 3, 2024

So _check_selector_method() checks if self.selector is None and asserts that are after it should do the same (those asserts are only needed for typing as mypy can't understand that _check_selector_method() did the same check)

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

Successfully merging a pull request may close this issue.

3 participants