avinashbot / redd

Redd is a batteries-included API wrapper for reddit.
MIT License
186 stars 75 forks source link

PaginatedListing returns empty Submission objects #71

Closed AlfredoRamos closed 7 years ago

AlfredoRamos commented 7 years ago

Hi,

I've been using the new 0.9.0.pre.3 prerelease and I've noticed that when checking if a list is empty, PaginatedListing returns a list of empty Submission objects.

Example:

links = session.subreddit(...).new(
  before: 't3_xxxxx'
)

With redd v0.8.8

p links.to_a
# => []

With redd v0.9.0.pre.3

p links.to_a
# => [#<Redd::Models::Submission (unloaded): []>, #<Redd::Models::Submission (unloaded): []>, ...]

I'm trying to check if there's new submissions, so with the previous test links.to_a should be empty ([]) because there's no new links after that fullname, however with the 0.9.0.pre.3 prerelease all the submissions are listed, but they all are empty Submission objects.

With this new behavior links.to_a.empty? never returns true even if there's no new submissions.

avinashbot commented 7 years ago

Hi! Thanks for waiting, I have a fix lined up for you. 😃

There isn't a fix for the "empty" submission objects. I've changed the architecture so that every attribute is lazily loaded. So the attributes are there, not just printed, but you can convert the model to Hash with to_h to view all attributes.

P.S. Sorry about the delay, I've been a bit busy.

AlfredoRamos commented 7 years ago

Thank you, it now works as expected.