Search Results

When you get a list of results back from a query, the first element is always the most recently created object (transaction, subscription, etc.).

Searches return a ResourceCollection which can be iterated over like a list.

search_results = braintree.Transaction.search([
    braintree.TransactionSearch.amount <= "20.00"
])

for transaction in search_results.items:
    print(transaction.id)
Python

Race conditions

To optimize the processing of large searches, data is retrieved from the server lazily.

Initially, the server returns a list of ids that matched the search criteria. While you're iterating over search results, the data for each record is fetched dynamically. This causes race conditions to exist when records are modified on the server while you are iterating over them.

Records are deleted

If a record is deleted server-side while you are iterating over the results, that record is skipped.

Records are updated

If a record is updated server-side while you are iterating over the results, one of two things could happen:

  • the record still matches the search criteria and the modified record is returned
  • the record no longer matches the search criteria and is skipped

Maximum size

Because of the race conditions described above, you cannot know how many search results you have while iterating over them. You do, however, know the maximum number of results that will be given.

search_results = braintree.Transaction.search([
    braintree.TransactionSearch.amount <= "20.00"
])

search_results.maximum_size
# e.g. 33
Python

Search Limit

We currently cap searches to 10,000 maximum results.