I have implemented a code to calculate api time.
@api.app.before_request
def before_request():
g.request_start_time = time.time()
@api.app.after_request
def after_request():
elapsed = time.time() - g.request_start_time ------> Error here.
I am having error for ~1-2% api calls.
Error:
'_AppCtxGlobals' object has no attribute 'request_start_time'
I am not able to debug this. This can only happen if :
- the api does not pass through before_request function.
- the global context get reset in between the code.
First seems not to be happen as every api request should pass the before_request function. I am not able to find when the second case can occur. What are the scenarios when the global context get reset in between call.
Is there anything I am missing here ?
EDIT:
I have been observing the cases when this error is occurring and found the similarity that all calls were having 400 BAD REQUEST
. But I am still not able to get the root cause of this.