And what "normal cursor code which barfs" are you talking about?
I don't see any references to the "normal cursor" code, you even rewrote the fetching logic: fetch_next_batch(), I can't really see anything that is shared?