Skip to content

Wrong behavior saving project variables when environment scopes are configured. #1125

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

Closed
bymarshall opened this issue Jun 22, 2020 · 1 comment · Fixed by #2927
Closed

Wrong behavior saving project variables when environment scopes are configured. #1125

bymarshall opened this issue Jun 22, 2020 · 1 comment · Fixed by #2927

Comments

@bymarshall
Copy link

bymarshall commented Jun 22, 2020

Description of the problem, including code/CLI snippet

If environment scopes are used in project variables, modifying and saving a project variable with a specific "environment_scope" is always altering the variable with the last defined scope.

Example:

>>> variables = project.variables.list()
>>> for variable in variables:
...     print("key: %s scope: %s" % (variable.key, variable.environment_scope))
... 
key: SCOPE_VARIABLE scope: qa
key: SCOPE_VARIABLE scope: prod
key: SCOPE_VARIABLE scope: test
>>> for variable in variables:
...    if variable.environment_scope == "prod":
...        variable.value="new_value"
...        variable.save()
...        print(variable.attributes)
... 
{'variable_type': 'env_var', 'key': 'SCOPE_VARIABLE', 'value': 'new_value', 'protected': False, 'masked': False, 'environment_scope': 'test', 'project_id': 123}

The variable with scope "prod" has not been modified, instead the variable with scope "test" is altered.

Expected Behavior

The variable with the specified scope should be updated.

Actual Behavior

The last scope defined for the variable is always taking precedence over the scope of the current variable that is going to be updated..

Specifications

  • python-gitlab version: 2.3.1
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 13.0.5
@acdha
Copy link

acdha commented Apr 28, 2021

This might have some relation to #1387 — the default manager seems to ignore the environment scopes and requires passing something like filter={"environment_scope": i.environment_scope} to save(), delete(), etc.

JohnVillalovos added a commit that referenced this issue Jul 13, 2024
Add a note about using `filter` when updating a variable.

Closes: #2835
Closes: #1387
Closes: #1125
JohnVillalovos added a commit that referenced this issue Jul 13, 2024
Add a note about using `filter` when updating a variable.

Closes: #2835
Closes: #1387
Closes: #1125
JohnVillalovos added a commit that referenced this issue Jul 13, 2024
Add a note about using `filter` when updating a variable.

Closes: #2835
Closes: #1387
Closes: #1125
JohnVillalovos added a commit that referenced this issue Jul 15, 2024
Add a note about using `filter` when updating a variable.

Closes: #2835
Closes: #1387
Closes: #1125
@nejch nejch closed this as completed in c378817 Jul 15, 2024
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 a pull request may close this issue.

2 participants