zenpy icon indicating copy to clipboard operation
zenpy copied to clipboard

`SearchExportResultGenerator.next()` raises `IndexError`

Open cbini opened this issue 1 year ago • 5 comments

https://github.com/facetoe/zenpy/blob/e3013a963d9f2a3e68f25442d0ed0d58ebe61646/zenpy/lib/generator.py#L51

I'm iterating over a SearchExportResultGenerator, and for some reason it's producing IndexError: list index out of range. This has worked without issue for every other search I've done, but somehow these parameters are breaking it:

  • updated > 2017-11-30T23:59:59+00:00
  • updated < 2018-01-01T00:00:00+00:00

Here's my function call:

archived_tickets = zendesk.search_export(
    type="ticket", status="closed", updated_between=[start_date, end_date]
)

I'm pretty stumped so maybe there's a bug somewhere?

cbini avatar Dec 12 '23 19:12 cbini

It could be that the range is too big? I'll have to look at the documentation to see how wide the date range you specified is "legal" for. :)

cryptomail avatar Dec 14 '23 16:12 cryptomail

Maybe? It's only a month, and the strange part is that I've done this for every month going back to 2012, but that's the only one that fails with the out of range error.

Perhaps there's a cap on number of records search export will return and for some reason that month is just ridiculously high?

cbini avatar Dec 14 '23 17:12 cbini

Yes, that could be it @cbini :I Also, at the risk of too much information, we have "protectionst" measures for queries that are too onerous and taxing on our systems. Can you try to winnow down the data to maybe 15 days (or bisect thereof).

cryptomail avatar Dec 15 '23 20:12 cryptomail

Yeah, it's not too big a deal. I threw it into a try/except block so that it stops iterating if it hits that error, but I figured you might want to know.

cbini avatar Dec 18 '23 15:12 cbini

I've hit the same issue. The problem occurs when the number of items in results is a multiple of 100 i.e. of the page-size. The StopIterration condition here: https://github.com/facetoe/zenpy/blob/40222cc450e84aaf499d3d4f98e9b77446923056/zenpy/lib/generator.py#L49 will never be True since the values list is always extended rather than replaced. A possible fix would be to replace lines 47-50:

        if self.position >= len(self.values):
            self.handle_pagination()
        if len(self.values) < 1:
            raise StopIteration()

by

        if self.position >= len(self.values):
            self.handle_pagination()
            ifself.position >= len(self.values):
                raise StopIteration()

Until this is done, you can catch the IndexError at the application level and ignore it if the number of fetched items is a multiple of 100.

ben-lorisai avatar Jan 14 '24 07:01 ben-lorisai

Wait I think I fixed this from another issue :)

cryptomail avatar May 19 '24 00:05 cryptomail