Fix KeyError on API failures and pickle error in Python 3.13 (#9)#10
Open
parthashirolkar wants to merge 1 commit intoaddypy:masterfrom
Open
Fix KeyError on API failures and pickle error in Python 3.13 (#9)#10parthashirolkar wants to merge 1 commit intoaddypy:masterfrom
parthashirolkar wants to merge 1 commit intoaddypy:masterfrom
Conversation
- Add proper error handling in get_data() when get_resource_info() returns empty dict - Create _make_request_for_pool() for multiprocessing workers to avoid pickle errors - get_api_records() now uses non-decorated function to prevent multiprocessing issues - Fixes addypy#9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two critical bugs reported in issue #9:
Bug #1: KeyError when API times out or returns errors
get_data()crashes withKeyError: 'total'becauseget_resource_info()returns an empty dict{}but the code tries to access["total"]directly.resource_infois empty or doesn't contain"total"before accessing it. Now raises a clearValueErrorwith a helpful message.Bug #2: Pickle error in Python 3.13 with multiprocessing
@retrydecorator onmake_request_with_retry()creates unpicklable state (an RLock), causingmultiprocessing.pool.MaybeEncodingError: cannot pickle '_thread.RLock' objectwhenpool.map()tries to serialize results from worker processes._make_request_for_pool(), a non-decorated version of the request function specifically for multiprocessing workers. This avoids the pickle error while maintaining the retry logic for non-multiprocessing use cases.Changes
_make_request_for_pool()function for multiprocessing workersget_api_records()to use the non-decorated functionget_data()to check for missing"total"keyValueErrorinstead of crashing withKeyErrorTesting
Both fixes have been tested:
get_resource_info()now properly handles API failures without crashingget_data()works with multiprocessing in Python 3.13 without pickle errorsFixes #9