I've done a Python program that reads data from GCP, GKE etc, compile some of them in a spreadsheet and replace placeholder text in a slide for reporting purposes.
I have several functions that call the slide replacing text function (that use the replaceAllText method of the slide API). It's currently making around 70 calls of that function, and so, 70 requests.
I know that I can use the batch.add() method to make fewer requests but here is my problem. The replacing function is called a lot so I tried to use a global variable for my batch object definition : batch_slide = SLIDE_SERVICE.new_batch_http_request()
In the replacing function I used the keyword global in front of the variable. In the main function I execute the batch when I need it to but now the result in the slide is chaotic.
When I used one request per replacement, everything was perfect, every field replaced correctly, but now with one batch, it's not. It seems random as I run it multiple times and the replaced field changed every time.
I put wait times after the execution to maybe ive it time to replace before doing other stuff but doesn't seems to fix it. I didn't find yet how to inspect my batch_slide object, it's not iterable.
Any help is appreciated, ask for more details if needed.
So for anyone wanting to do something similar here is how I did it.
I used a global variable on the request instead of the batch object, and when needed calling a batch execute with the big request.
The request will maybe take a bit more time to process but you only make one this way so no risks of timeouts. Just stacks the request list.
Google SLIDE API global batch.add request Python