Created
September 24, 2014 12:25
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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