Skip to content

Wrong behaviour deleting variable #1387

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
Gisson opened this issue Mar 30, 2021 · 5 comments · Fixed by #2927
Closed

Wrong behaviour deleting variable #1387

Gisson opened this issue Mar 30, 2021 · 5 comments · Fixed by #2927

Comments

@Gisson
Copy link

Gisson commented Mar 30, 2021

Description of the problem, including code/CLI snippet

On a project where we have the same variable names in different environments, running the code below to delete a variable produces a scope error when running it.

variable.delete()

Expected Behavior

Successful variable deletion

Actual Behavior

Produces the error below:

Traceback (most recent call last):
  File "/repo/lib/python3.8/site-packages/gitlab/exceptions.py", line 279, in wrapp
ed_f
    return f(*args, **kwargs)
  File "/repo/lib/python3.8/site-packages/gitlab/mixins.py", line 341, in delete
    self.gitlab.http_delete(path, query_data=query_data, **kwargs)
  File "/repo/lib/python3.8/site-packages/gitlab/__init__.py", line 744, in http_de
lete
    return self.http_request("delete", path, query_data=query_data, **kwargs)
  File "/repo/lib/python3.8/site-packages/gitlab/__init__.py", line 567, in http_request
    raise GitlabHttpError(
gitlab.exceptions.GitlabHttpError: 409: There are multiple variables with provided parameters. Please use 'filter[environment_scope]'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/repo/lib/python3.8/site-packages/gitlab/mixins.py", line 403, in delete
    self.manager.delete(self.get_id(), query_data)
  File "/repo/lib/python3.8/site-packages/gitlab/exceptions.py", line 281, in wrapp
ed_f
    raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabDeleteError: 409: There are multiple variables with provided parameters. Please use 'filter[environment_scope]'

Specifications

  • python-gitlab version: 2.6.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 13.9
@markuman
Copy link

I run into the same issue at the same time! :)

>>> project.variables.delete(existing_variables[2].get_id(), filter={'environment_scope': 'b'})

Works for me.

@Gisson
Copy link
Author

Gisson commented Mar 31, 2021

I've confirmed that this workaround does work. However this can delete unwanted variables if we don't make sure that the environment scope in the filter is not the same as the one on the variable we fetched.

@markuman
Copy link

>>> project.variables.delete(existing_variables[2].get_id(), filter={'environment_scope': existing_variables[2].environment_scope})

sadly, there is no other method in the underlying v4 api.

@Gisson
Copy link
Author

Gisson commented Apr 5, 2021

But it is possible to alter the http_delete method to have query arguments and pass it the query arguments we need, that way the variable.delete method would work (tried it on a previous version).

@acdha
Copy link

acdha commented Apr 28, 2021

It seems like the manager could default to specifying that filter if the environment_scope is defined or at least be mentioned in the documentation since it's a fairly confusing error and people are likely to be very cautious about poking into the internals for something important like this.

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
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.

3 participants