Sitelet https://github.com/python-gitlab/python-gitlab/pull/3440
Skip to content

fix: add cancel API for BulkImport (#3292) - #3440

Open
AquaticAzelf wants to merge 1 commit into
python-gitlab:mainfrom
AquaticAzelf:fix/bulk-import-cancel-3292
Open

fix: add cancel API for BulkImport (#3292)#3440
AquaticAzelf wants to merge 1 commit into
python-gitlab:mainfrom
AquaticAzelf:fix/bulk-import-cancel-3292

Conversation

@AquaticAzelf

Copy link
Copy Markdown

Fixes #3292.

Problem

API POST /bulk_imports/:id/cancel documented at https://docs.gitlab.com/api/bulk_imports/#cancel-a-migration was missing in BulkImport model (gitlab/v4/objects/bulk_imports.py:17). No way to cancel a migration via python-gitlab.

Solution

  • gitlab/v4/objects/bulk_imports.py:1-39 — add imports typing.Any, requests, gitlab.cli, gitlab.exceptions, and new method:
@cli.register_custom_action(cls_names="BulkImport")
@exc.on_http_error(exc.GitlabCancelError)
def cancel(self, **kwargs: Any) -> dict[str, Any] | requests.Response:
    path = f"{self.manager.path}/{self.encoded_id}/cancel"
    return self.manager.gitlab.http_post(path, **kwargs)

Mirrors ProjectPipeline.cancel (gitlab/v4/objects/pipelines.py:67-80), single file, 15 lines, no cross-folder changes. Uses existing GitlabCancelError (no new exception).

Verification (folder-local only, no global installs)

  • Cloned to C:\Users\Azelf\AppData\Local\Temp\opencode\python-gitlab-fix, python -m venv .venv, pip install -e . (folder-local), pip install responses pytest
  • Existing tests still pass: pytest tests/unit/objects/test_bulk_imports.py -v6 passed
  • New behavior:
import responses; from gitlab import Gitlab
gl = Gitlab('http://localhost', private_token='test')
with responses.RequestsMock() as rsps:
    rsps.add(GET, "http://localhost/api/v4/bulk_imports/1", json={"id":1}, status=200)
    rsps.add(POST, "http://localhost/api/v4/bulk_imports/1/cancel", json={"id":1,"status":"finished"}, status=200)
    m = gl.bulk_imports.get(1); assert m.cancel()["status"]=="finished"
  • BulkImport.cancel exists, CLI bulk-import cancel registered.

Stars: 2472★ (not zero), updated 2026, no duplicate PR (checked closed_by_pull_requests).

Closes #3292

Add BulkImport.cancel() to support POST /bulk_imports/:id/cancel per GitLab docs https://docs.gitlab.com/api/bulk_imports/#cancel-a-migration.

Mirrors ProjectPipeline.cancel pattern, uses GitlabCancelError and cli.register_custom_action, verified with responses mock and pytest.

Closes python-gitlab#3292
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.76%. Comparing base (3032667) to head (61ba418).

Files with missing lines Patch % Lines
gitlab/v4/objects/bulk_imports.py 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3440      +/-   ##
==========================================
- Coverage   95.78%   95.76%   -0.03%     
==========================================
  Files         100      100              
  Lines        6172     6181       +9     
==========================================
+ Hits         5912     5919       +7     
- Misses        260      262       +2     
Flag Coverage Δ
api_func_v4 83.85% <77.77%> (+0.05%) ⬆️
cli_func_v4 78.78% <77.77%> (-0.01%) ⬇️
unit 90.30% <77.77%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
gitlab/v4/objects/bulk_imports.py 94.11% <77.77%> (-5.89%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Add cancel bulk_import api

1 participant