Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fetching variable with environment scope raises 409 complaining about multiple variables with same key #3202

Copy link
Copy link
@elucify

Description

@elucify
Issue body actions

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
acdha and heinzz-da-ketchup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.