Description
Description of the problem, including code/CLI snippet
When attempting to fetch a project variable with a specific environment_scope
using the python-gitlab API (v5.6.0) against GitLab server (17.6.5-ee), the documented and intuitive approaches do not work. Specifically, neither passing environment_scope
nor filter_environment_scope
as arguments to ProjectVariableManager.get()
resolves the error 409: There are multiple variables with provided parameters. Please use 'filter[environment_scope]'
even when only two variables exist with unique environment scopes.
Example (all fail with 409 error):
src.variables.get("PUBLISH_TIMEOUT", "*")
src.variables.get("PUBLISH_TIMEOUT", environment_scope="*")
src.variables.get("PUBLISH_TIMEOUT", filter_environment_scope="*")
The only way to successfully fetch the correct variable is by using the undocumented query_parameters
argument, as discovered by reading the source code:
src.variables.get(
p.key,
query_parameters={"filter[environment_scope]": p.environment_scope}
)
This workaround is not documented and the error message does not guide the user to this solution. The documentation and exception message should be updated to clarify the correct usage.
Expected Behavior
Passing either environment_scope
or filter_environment_scope
as an argument to ProjectVariableManager.get()
should allow selection of the correct variable when multiple variables share the same key but have different environment scopes, as described in the GitLab API documentation. The library should transparently handle the filter parameter, or at least document the correct usage.
Actual Behavior
Passing environment_scope
or filter_environment_scope
as arguments to get()
results in a 409 error from the API:
gitlab.exceptions.GitlabGetError: 409: There are multiple variables with provided parameters. Please use 'filter[environment_scope]'
The only way to successfully retrieve the variable is by passing the filter as a query_parameters
dictionary, which is not documented (at least, not in the places where the documentation would be of use):
src.variables.get(
p.key,
query_parameters={"filter[environment_scope]": p.environment_scope}
)
Specifications
- python-gitlab version: 5.6.0
- Gitlab server version (or gitlab.com): v17.6.5-ee