adding a new method to retry jsonDecode errors#3
adding a new method to retry jsonDecode errors#3alexvarghese250 wants to merge 4 commits intomasterfrom
Conversation
|
Hey Gordon, so while reading through the code I noticed I can't get just return the value from .json().get('recipients') So i have two options, either create that lightweight wrapper class that holds the decoded json from the recipients output or just run .json().get(recipients) twice for every single call. How would i go about figuring out how expensive the .json() call is and could you walk me through how I should be going about making the light weight wrapper? |
|
refactored the code after talking to Gordon. Anna want to take a look and let me know what you think. |
| break | ||
| except JSONDecodeError: | ||
| page_attempts += 1 | ||
| if page_attempts > 3: |
There was a problem hiding this comment.
-- here it should be > or <? you want to continue trying to decode r until page_attempts reach 3 right?
-- also, I am not sure if it will catch JSONDecodeError if you don't put "except JSONDecodeError:" right after yield r.json()? my feeling is it might throw an error when you are on line 184 without even reaching line 190, but I am not sure.
-- on line 60 I think we don't need .json() anymore because we are giving it .json() already.
-- if there is an error with decoding and we have to retry decoding, we will be refetching the whole page again, is that the goal? The problem is with .json() not working properly or with page being broken?
There was a problem hiding this comment.
- changed it to <, it should be decoding until 3 attempts
- not sure if there is a problem with the decode statement but refactored just to be safe
- You are right about line 60 so I changed that
- The problem is with .json not working properly, sometimes there is an issue where it doesnt decode properly so I just want to try retrying that line again so we don't have to restart the whole tap
There was a problem hiding this comment.
Everything looks good! The only concern I have is that when we go from one retry to next if we are getting JSONDecoder error, I think we are repeating everything from line 174, i.e. getting the page again, no? If that's the case, then it's better to wrap .json() method into the for loop, i.e. something like this:
while page_attempts < 3:
try:
yield r.json()
except JSONDecodeError:
page_attempts += 1
if page_attempts =< 3:
continue
else:
logger.error(f'Status code throwing error {r.status_code}')
logger.error(f'Content for invalid request:\n{r.content}')
raise ValueError('Error parsing file...')
break
```
There was a problem hiding this comment.
So jsondecodeError seems like its a transient issue so I can't tell if the issue was with the api call or with the .json() method. I want to make the whole api call again just incase that the response we got back from the api is what is corrupted that this is a true retry. It's hard to replicate and test this so that is why I want to retry the whole block to make sure a retry fixes it.
There was a problem hiding this comment.
makes sense! then all good :)
No description provided.