Skip to content

Fix errors when a subreddit has <5 posts.#702

Merged
ChrisLovering merged 3 commits into
mainfrom
fix-reddit-index-error
Apr 23, 2021
Merged

Fix errors when a subreddit has <5 posts.#702
ChrisLovering merged 3 commits into
mainfrom
fix-reddit-index-error

Conversation

@ChrisLovering
Copy link
Copy Markdown
Member

Relevant Issues

Closes #701

Description

Changed a list slice from [1] to [0].
Added a min check for length of the respond, before shuffling.

Reasoning

If a subreddit has <2 posts, the posts[1] check would fail with an IndexError.
If the subreddit had less than 5 posts, then the k=5 check would also error. These changes harden the command for these edge cases.

Did you:

  • Join the Python Discord Community?
  • If dependencies have been added or updated, run pipenv lock?
  • Lint your code (pipenv run lint)?
  • Set the PR to allow edits from contributors?

If a subreddit has <2 posts, the posts[1] check would fail with an IndexError. If
the subreddit had less that 5 posts, then the k=5 check would also error. These changes
harden the command for these edge cases.
Copy link
Copy Markdown
Contributor

@ToxicKidz ToxicKidz left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Copy Markdown
Contributor

@Kronifer Kronifer left a comment

Choose a reason for hiding this comment

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

:shipit:

@Xithrius Xithrius added area: backend Related to internal functionality and utilities season: evergreen status: needs review Author is waiting for someone to review and approve type: bug Something isn't working labels Apr 23, 2021
Comment thread bot/exts/evergreen/reddit.py Outdated
Co-authored-by: Xithrius <15021300+Xithrius@users.noreply.github.com>
@ChrisLovering ChrisLovering requested a review from Xithrius April 23, 2021 11:28
Copy link
Copy Markdown
Contributor

@Xithrius Xithrius left a comment

Choose a reason for hiding this comment

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

It works well.

@ChrisLovering ChrisLovering enabled auto-merge April 23, 2021 13:20
@ChrisLovering ChrisLovering merged commit 2fe7815 into main Apr 23, 2021
@ChrisLovering ChrisLovering deleted the fix-reddit-index-error branch April 23, 2021 13:21
@Xithrius Xithrius removed the status: needs review Author is waiting for someone to review and approve label Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backend Related to internal functionality and utilities type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError: list index out of range

4 participants