Skip to content

fix: skip commits rejected by GitHub with HTTP 422 - #539

Open
iamshravanijadhav wants to merge 1 commit into
chaoss:mainfrom
iamshravanijadhav:fix-526-invalid-commit
Open

iamshravanijadhav wants to merge 1 commit into
chaoss:mainfrom
iamshravanijadhav:fix-526-invalid-commit

Conversation

@iamshravanijadhav

Copy link
Copy Markdown

Description
This PR fixes the HTTP 422 error that occurs when a commit is no longer available in the repository.

This PR fixes #526

Notes for Reviewers
The fix skips commits that return HTTP 422 and continues processing the remaining commits. I tested the changes in Docker, and all 9 tests passed.

  • Changes made:

-Added handling for HTTP 422 errors.
-Stopped retrying requests when GitHub returns HTTP 422.
-Added logging when a commit lookup fails with HTTP 422.
-Added tests for the retry policy and commit lookup error handling.

Signed commits

  • Yes, I signed my commits.

Generative AI disclosure

Please select one option:

  • This contribution was NOT assisted or created by Generative AI tools.
  • This contribution was assisted or created by Generative AI tools.

If AI tools were used, please provide details below:
- What tools were used? Chatgpt
- How were these tools used? I used ChatGPT to understand the HTTP 422 issue and debug it.
- Did you review these outputs before submitting this PR? Yes, I reviewed the changes and ran the tests.

Signed-off-by: Shravani <jadhavshravani223@gmail.com>
Comment on lines 64 to +77
# Try to get the login from the commit sha
if login == None or login == "":
login = get_login_with_commit_hash(logger, auth, contributor, repo_id)
if login is None or login == "":
try:
login = get_login_with_commit_hash(
logger, auth, contributor, repo_id
)
except httpx.HTTPStatusError as e:
if e.response.status_code == 422:
logger.warning(
f"Skipping commit {contributor.get('hash')} "
f"because GitHub returned HTTP 422."
)
continue
raise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, given the context surrounding this fix, it may be a better approach to find a different commit from that contributor (which is plumbing we don't fully have in place yet).

I can see potentially skipping the contributor for now though, especially if we add the above as a comment in hthis area of the code.

Comment on lines +224 to +225
if isinstance(exception, httpx.HTTPStatusError) and exception.response.status_code == 422:
return False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be a better fit with the existing code in this part of the codebase to create a new ResourceUnprocessable exception that we throw when the status is 422 and then include that in the list of exceptions not to retry here.

logger, auth, commit_data, repo_id=1
)

assert exc_info.value.response.status_code == 422

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a chance exc_info might not exist in this scope? maybe its worth indenting the assertions

Comment on lines +62 to +69
def test_422_response_is_not_retried(self, gda):
assert not GithubDataAccess._decide_retry_policy(
httpx.HTTPStatusError(
"422 Unprocessable Entity",
request=Mock(),
response=Mock(status_code=422),
)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is inside the TestEndpointUrl class. It should be moved to a top level function like the other tests added in this PR (or better yet, put in its own TestResponseErrors class to group the tests togethern

@iamshravanijadhav

Copy link
Copy Markdown
Author

Thank you for the review! I'll work on the suggested changes, update the exception handling and tests, and add the comment explaining the current approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[Celery Failure] HTTP 422 unprocessable entity collectoss.tasks.github.facade_github.tasks.insert_facade_contributors

2 participants