Conversation
censusgeocode re-raises RequestException and CensusGeocoder did not catch it, so a connection reset or a timeout ended the whole call -- including a batch job partway through its chunks. Adds a retries constructor argument and a _request helper that retries connection-level failures with 2 ** attempt backoff. The retry wraps the per-chunk call in geocode_address_batch, so completed chunks are not re-sent. The default of 0 preserves today's behavior exactly, and a negative value is rejected rather than silently skipping the request. Only RequestException is retried. The Census API's own error statuses do not raise -- censusgeocode never calls raise_for_status -- so they are out of scope here.
This was referenced Aug 28, 2026
bmos
suggested changes
Aug 29, 2026
Comment on lines
+45
to
+46
| def _request(self, func, *args, **kwargs): | ||
| # Retries transient network failures only; see the class docstring for the limits. |
Collaborator
There was a problem hiding this comment.
Suggested change
| def _request(self, func, *args, **kwargs): | |
| # Retries transient network failures only; see the class docstring for the limits. | |
| def _request(self, func, *args, **kwargs): | |
| """ | |
| Facilitate retrying requests when network failures occur. | |
| Failed requests resulting in retries will be logged. | |
| See class docstring for more information. | |
| Args: | |
| func (Callable): function to wrap with retry logic | |
| Returns: | |
| Value returned by provided callable | |
| """ |
Doesn't have to be exactly that, but a docstring here would be nice.
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.
What is this change?
censusgeocodere-raisesRequestExceptionandCensusGeocodernever caught it, so a singleconnection reset or timeout ended the whole call. For
geocode_address_batchthat means a longjob dies partway through its chunks.
retriesconstructor argument and a_requesthelper that retries connection-levelfailures with
2 ** attemptbackoff. The retry wraps the per-chunk call ingeocode_address_batch, so completed chunks are never re-sent.Considerations for discussion
0, which preserves today's behavior exactly. Retrying by default wouldchange request timing for every existing user and could multiply load on a government endpoint,
so it seemed wrong to opt everyone in.
Newmodedefaults to 2 retries if you would rather thismatched that.
RequestExceptionis retried, and that is a real limit worth naming.censusgeocodenever calls
raise_for_status(), so the Census API's own error responses do not raise: a 5xxreaches
_fetchas a JSON decode failure and surfaces asValueError("Unable to parse response from Census"), which is indistinguishable from a genuineparse problem. Retrying
ValueErrorwould therefore also retry real bugs, so I left it alone.Making HTTP status failures visible is a separate change and I have filed it separately.
Redshift,Postgres,MySQLandBraintree.How to test the changes (if needed)
Four new tests cover recovery after transient failures, re-raising once retries are exhausted,
the no-retry default, and that all four public methods are wrapped.
Breaking Changes
Breaking changes are changes to our public API which may require existing users to change their code. If there are no breaking changes, any existing parsons user should not need to do anything after updating their parsons version.
Does this PR introduce breaking changes?
Details (if needed)
0, which makes exactly one attempt and neversleeps -- identical to current behavior. No signature or return-type change.