Skip to content

Conversation

@pspacek
Copy link
Contributor

@pspacek pspacek commented Oct 18, 2022

Fixes: #2325

@lmilbaum
Copy link

Unit tests might increase the confidence that the code is working as expected. Would you mind adding unit tests?

Copy link
Member

@nejch nejch left a 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.

@nejch
Copy link
Member

nejch commented Oct 20, 2022

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 :)

@nejch
Copy link
Member

nejch commented Dec 4, 2022

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!

@pspacek
Copy link
Contributor Author

pspacek commented Dec 5, 2022

@nejch I'm sorry, I have no time to work on this. Feel free to do whatever you like.

@nejch nejch force-pushed the http-409-lock-retry branch from fdb1d2c to 25446cf Compare December 5, 2022 20:48
Comment on lines +379 to +389
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
Copy link
Member

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).

@nejch nejch changed the title Draft: feat(client): automatically retry on HTTP 409 Resource lock feat(client): automatically retry on HTTP 409 Resource lock Dec 5, 2022
Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

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

This LGTM but I added a commit in 25446cf to finish the PR so will need someone else to do the merge.

Thanks again @pspacek!

@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2022

Codecov Report

Merging #2326 (1a37bab) into main (c7cf0d1) will increase coverage by 0.00%.
The diff coverage is 90.90%.

@@           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     
Flag Coverage Δ
api_func_v4 82.58% <54.54%> (+<0.01%) ⬆️
cli_func_v4 82.83% <45.45%> (-0.06%) ⬇️
unit 87.48% <81.81%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gitlab/client.py 98.38% <90.90%> (-0.18%) ⬇️
gitlab/v4/objects/__init__.py 100.00% <0.00%> (ø)
gitlab/v4/objects/resource_groups.py 100.00% <0.00%> (ø)
gitlab/v4/objects/projects.py 98.86% <0.00%> (+<0.01%) ⬆️

@nejch nejch force-pushed the http-409-lock-retry branch from 25446cf to 1a37bab Compare December 18, 2022 11:47
@nejch
Copy link
Member

nejch commented Dec 19, 2022

Unit tests might increase the confidence that the code is working as expected. Would you mind adding unit tests?

@lmilbaum I've added a commit on top of the author's to rework and add tests (1a37bab). Maybe you can take a look and we can merge before the next release.

@lmilbaum lmilbaum self-requested a review December 19, 2022 20:02
Copy link

@lmilbaum lmilbaum left a comment

Choose a reason for hiding this comment

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

LGTM

return False
if result.status_code in gitlab.const.RETRYABLE_TRANSIENT_ERROR_CODES:
return True
if result.status_code == 409 and "Resource lock" in result.reason:

Choose a reason for hiding this comment

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

Doesn't seem to work for us - could it be because Resource lock is in the response body rather than the HTTP reason (Conflict)?

dd-mergequeue bot pushed a commit to DataDog/datadog-agent that referenced this pull request Nov 28, 2025
…3648)

### Motivation
The python-gitlab fix (python-gitlab/python-gitlab#2326) for 409 Resource lock retries checks `result.reason`, but GitLab sends `Conflict` (standard HTTP reason phrase) while `Resource lock` is in the response body. The check never matches, so retries never happen:
```
$ dda inv -- pipeline.auto-cancel-previous-pipelines
[...]
gitlab.exceptions.GitlabHttpError: 409: 409 Conflict: Resource lock
                                        ^ reason      ^ response body
```
Example: https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1262109099

### What does this PR do?
This patch adds HTTP `409` to GitLab's API retriable transient error codes as a lightweight workaround, allowing all 409 errors to be retried when `retry_transient_errors=True` (our case).

### Additional Notes
Will file an issue upstream.

Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com>
github-actions bot pushed a commit to Bettdatt/datadog-agent that referenced this pull request Nov 28, 2025
…taDog#43648)

### Motivation
The python-gitlab fix (python-gitlab/python-gitlab#2326) for 409 Resource lock retries checks `result.reason`, but GitLab sends `Conflict` (standard HTTP reason phrase) while `Resource lock` is in the response body. The check never matches, so retries never happen:
```
$ dda inv -- pipeline.auto-cancel-previous-pipelines
[...]
gitlab.exceptions.GitlabHttpError: 409: 409 Conflict: Resource lock
                                        ^ reason      ^ response body
```
Example: https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1262109099

### What does this PR do?
This patch adds HTTP `409` to GitLab's API retriable transient error codes as a lightweight workaround, allowing all 409 errors to be retried when `retry_transient_errors=True` (our case).

### Additional Notes
Will file an issue upstream.

Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com> fcb5852
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature request] auto-retry when HTTP 409 Conflict: Resource lock is received

7 participants