Skip to content

Instantly share code, notes, and snippets.

@sebastiansibelle
Created September 24, 2014 12:25
Show Gist options
  • Save sebastiansibelle/4a374f1ffa4ebfc40633 to your computer and use it in GitHub Desktop.
Save sebastiansibelle/4a374f1ffa4ebfc40633 to your computer and use it in GitHub Desktop.
An example illustrating the bug in the Customer.list function in a Rails installation.
limit = 5
list = ChargeBee::Customer.list({:limit => limit})
logger.debug "#### First List"
# Retrieves the first list as expected
list.each do |entry|
customer = entry.customer
logger.debug customer.email
end
# Retrieves the offset as expected
offset = list.next_offset
logger.debug "#### Offset"
logger.debug offset
# If the list has > limit rows
logger.debug "#### Subsequent lists"
while !list.next_offset.blank? do
# We supply the offset from the previous call
logger.debug "#### Get next list"
logger.debug offset
list = ChargeBee::Customer.list({:limit => limit, :offset => offset})
# UHOH! The same rows are retrieved, even though we supplied an offset :(
list.each do |entry|
customer = entry.customer
logger.debug customer.email
end
logger.debug list.inspect
# update the offest
offset = list.next_offset
end
# This script will never end if the list > limit rows. BUG!
logger.debug "end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment