Skip to content

Commit

Permalink
Merge pull request #220 from praw-dev/fix_notes
Browse files Browse the repository at this point in the history
Fix iterating mod notes when there is more than a single page
  • Loading branch information
LilSpazJoekp committed Dec 9, 2022
2 parents 3894fca + dbd1cf0 commit 08f4012
Show file tree
Hide file tree
Showing 6 changed files with 513 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Async PRAW follows `semantic versioning <http://semver.org/>`_.
Unreleased
----------

**Fixed**

- An issue with with iterating :class:`.ModNote` when a user has more than a hundred
notes.

7.6.1 (2022/11/28)
------------------

Expand Down
6 changes: 4 additions & 2 deletions asyncpraw/models/listing/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ async def _next_batch(self):
if not self._listing:
raise StopAsyncIteration()

if self._listing.after and self._listing.after != self.params.get("after"):
self.params["after"] = self._listing.after
if self._listing.after and self._listing.after != self.params.get(
self._listing.AFTER_PARAM
):
self.params[self._listing.AFTER_PARAM] = self._listing.after
else:
self._exhausted = True
2 changes: 2 additions & 0 deletions asyncpraw/models/listing/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Listing(AsyncPRAWBase):
"""A listing is a collection of :class:`.RedditBase` instances."""

AFTER_PARAM = "after"
CHILD_ATTRIBUTE = "children"

def __len__(self) -> int:
Expand Down Expand Up @@ -44,6 +45,7 @@ class ModeratorListing(Listing):
class ModNoteListing(Listing):
"""Special Listing for handling :class:`.ModNote` lists."""

AFTER_PARAM = "before"
CHILD_ATTRIBUTE = "mod_notes"

@property
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def cassette_tracker(self):
existing_cassettes.add(cassette.replace(".json", ""))
yield
unused_cassettes = existing_cassettes - used_cassettes
if unused_cassettes:
if unused_cassettes and os.getenv("ensure_no_unused_cassettes", "0") == "1":
raise AssertionError(
f"The following cassettes are unused: {', '.join(unused_cassettes)}."
)
Expand Down

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions tests/integration/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,18 @@ async def test_notes(self, reddit):
assert notes[1].user.name.lower() == "watchful12"
assert notes[2] is None

async def test_notes_iterate(self, reddit):
reddit.read_only = False
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
distinct_ids = set()
count_notes = 0
async for note in subreddit.mod.notes.redditors("watchful12", limit=None):
distinct_ids.add(note.id)
count_notes += 1

assert len(distinct_ids) == 359
assert count_notes == 359

async def test_reports(self, reddit):
reddit.read_only = False
count = 0
Expand Down

0 comments on commit 08f4012

Please sign in to comment.