Skip to content

fix(client): resolve double /api/v4 segments in _build_url method #3247

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

netflash
Copy link

Description

This PR fixes a longstanding bug in the _build_url method that causes double /api/v4 segments in URLs when paths start with /api/v4/.

Problem

When calling _build_url with a path like /api/v4/projects/123/security_settings, the method returns:

https://api.example.com/api/v4/api/v4/projects/123/security_settings

Instead of the expected:

https://api.example.com/api/v4/projects/123/security_settings

Solution

The fix detects paths starting with /api/v4/ and removes the duplicate prefix before constructing the final URL.

Testing

  • ✅ Added test case that reproduces the bug
  • ✅ All existing tests still pass
  • ✅ Fix maintains backward compatibility
  • ✅ Tested across multiple versions (5.0.0, 5.6.0, 6.0.0, 6.1.0, 6.2.0)

Impact

This bug has existed in all versions from 5.0.0 onwards and affects any code using paths starting with /api/v4/. The fix resolves a real-world issue encountered when trying to enable GitLab secret detection features.

Closes #3246

- Fix URL construction bug when paths start with /api/v4/
- Add test case to reproduce and verify the fix
- Maintain backward compatibility with existing behavior
- Resolves longstanding bug affecting all versions from 5.0.0+

Closes python-gitlab#3246
@netflash netflash force-pushed the fix/url-construction-bug branch from 68e8b67 to d158706 Compare August 14, 2025 05:17
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.32%. Comparing base (397cf39) to head (d158706).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3247   +/-   ##
=======================================
  Coverage   97.32%   97.32%           
=======================================
  Files          98       98           
  Lines        6062     6065    +3     
=======================================
+ Hits         5900     5903    +3     
  Misses        162      162           
Flag Coverage Δ
api_func_v4 83.52% <33.33%> (-0.08%) ⬇️
cli_func_v4 84.64% <33.33%> (-0.03%) ⬇️
unit 90.20% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
gitlab/client.py 98.74% <100.00%> (+<0.01%) ⬆️
🚀 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.

URL Construction Bug: Double /api/v4 segments in _build_url method
1 participant