Skip to content

Embed: don't fail while querying sections with bad id #8084

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

Merged
merged 3 commits into from
May 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions readthedocs/embed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,15 @@ def parse_sphinx(content, section, url):
for element_id in elements_id:
if not element_id:
continue
query_result = body_obj(f'#{element_id}')
if query_result:
break
try:
query_result = body_obj(f'#{element_id}')
if query_result:
break
except Exception: # noqa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the exception we catch here more specific?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exception comes from a third party package that is used from pyquery, I don't like having imports from packages that aren't listed in our requirements, also there may be more exceptions than the one reported, so we would still need to have a broader check. And, only the pyquery execution is inside the try block, so no need to scope it down.

log.info(
'Failed to query section. url=%s id=%s',
url, element_id,
)

if not query_result:
selector = f':header:contains("{escaped_section}")'
Expand Down