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

Fix #3535 - Genius Null Check #3554

Merged
merged 6 commits into from
Apr 17, 2020
Merged

Fix #3535 - Genius Null Check #3554

merged 6 commits into from
Apr 17, 2020

Conversation

thejli21
Copy link
Contributor

Added the null check with a unit test and sample Genius page.

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Looking good so far; thanks!!

Would you mind trimming down some of the bulky markup in the sample HTML file? There are two reasons to do this: (1) saving space, and (2) avoiding intellectual property infringement. That is, while there are no actual lyrics in there, there is plenty of stuff that could be construed as "owned" by Genius. Is it possible to have a meaningful test with only a minimal/stripped-down skeleton of the real page?

Also, would you mind adding a quick note about the fix to the changelog (under docs)?

lyrics = html.find("div", class_="lyrics").get_text()
try:
lyrics = html.find("div", class_="lyrics").get_text()
except AttributeError as exc:
Copy link
Member

Choose a reason for hiding this comment

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

Cool! I think this might be a little clearer (and not require the code-like reasoning that currently appears in a comment) if we instead check specifically for None instead of generically for a missing attribute:

lyrics_div = html.find(...)
if lyrics_div is None:
    self._log...
    return None
lyrics = lyrics_div.get_text()

What do you think about that minor restructuring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like it should have the same functionality, I'll rewrite it and test it again to make sure! Checking for None in general seems like a better failsafe, I think I was just using try-except because that's what the other error checking seemed to be doing.

try:
self.assertEqual(genius.lyrics_from_song_api_path('/nolyric'),
None)
except AttributeError:
Copy link
Member

Choose a reason for hiding this comment

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

Instead of catching the exception and assessing, I think we can just let the exception through. That is, you can remove the try/except handler here completely—the test will error out if the bug exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing!

@thejli21
Copy link
Contributor Author

@sampsyo made the recommended changes, trimmed the example html, and made a small note in the changelog.

@sampsyo sampsyo merged commit e0fc7b1 into beetbox:master Apr 17, 2020
sampsyo added a commit that referenced this pull request Apr 17, 2020
sampsyo added a commit that referenced this pull request Apr 17, 2020
@sampsyo
Copy link
Member

sampsyo commented Apr 17, 2020

Awesome; looks great! Thanks for taking care of this!

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 this pull request may close these issues.

2 participants