-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(client): automatically retry on HTTP 409 Resource lock #2326
Conversation
Unit tests might increase the confidence that the code is working as expected. Would you mind adding unit tests? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pspacek thanks for the quick work here! Just a few nits.
Regarding unit tests and your question in #2325 (comment).
We have some vendored code from httmock for a similar reason (redirects). I think you might be able to reuse it here?
https://github.com/python-gitlab/python-gitlab/blob/main/tests/unit/helpers.py
See how it's used in the redirect tests:
https://github.com/python-gitlab/python-gitlab/blob/main/tests/unit/test_gitlab_http_methods.py#L310-L317
Let us know if you need help with that :) That's a shame about responses though.
And @pspacek we're also ok to go ahead without the unit tests if it's too complicated and we open a follow-up issue to resolve on our end :) |
Hi @pspacek! Let us know if you'd like to finish this PR, or if we should push to your branch to get this merged (either way you'll be credited as the commit author). Thanks again for the contribution! |
@nejch I'm sorry, I have no time to work on this. Feel free to do whatever you like. |
fdb1d2c
to
25446cf
Compare
def response_callback( | ||
response: requests.models.Response, | ||
) -> requests.models.Response: | ||
"""We need a callback that adds a resource lock reason only on first call""" | ||
nonlocal retried | ||
|
||
if not retried: | ||
response.reason = "Resource lock" | ||
|
||
retried = True | ||
return response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're mostly doing this because responses
doesn't support mocking Response.reason
as @pspacek already found out in #2325 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report
@@ Coverage Diff @@
## main #2326 +/- ##
=======================================
Coverage 96.13% 96.13%
=======================================
Files 84 85 +1
Lines 5534 5569 +35
=======================================
+ Hits 5320 5354 +34
- Misses 214 215 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
25446cf
to
1a37bab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes: #2325