Skip to content

Deleting a label fails with 404 #1867

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
just-doit opened this issue Feb 1, 2022 · 7 comments · Fixed by #1868
Closed

Deleting a label fails with 404 #1867

just-doit opened this issue Feb 1, 2022 · 7 comments · Fixed by #1868

Comments

@just-doit
Copy link

just-doit commented Feb 1, 2022

Description of the problem, including code/CLI snippet

I'm trying to delete all labels from a given project using this code:

# connect to Gitlab
gl = gitlab.Gitlab(GITLAB_URL, private_token=GITLAB_TOKEN)
gl.auth()

# Get GitLab project
gl_project = gl.projects.get(GITLAB_PROJECT_ID)

# delete ALL labels
for gl_label in gl_project.labels.list(all=True):
    gl_label.delete()

The token works since I've used it successfully to do some other API calls before. The same user is able to delete labels manually via Web-UI.

Expected Behavior

I would expect the code not to throw a `gitlab.exceptions.GitlabDeleteError: 404: 404 Label Not Found'

Actual Behavior

The delete call fails with a gitlab.exceptions.GitlabDeleteError: 404: 404 Label Not Found.

Specifications

  • python-gitlab version: 3.1.1
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): GitLab Enterprise Edition 14.5.0-ee
@nejch
Copy link
Member

nejch commented Feb 1, 2022

Thanks @just-doit for the report, could you maybe add gl.enable_debug() and show the output here, just redact the token if it appears anywhere.

@just-doit
Copy link
Author

Hi,
this is the complete output:

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): <server>:443
send: b'GET /api/v4/user HTTP/1.1\r\nHost: <server>\r\nUser-Agent: python-gitlab/3.1.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: <secret>\r\nContent-type: application/json\r\n\r\n'
DEBUG:urllib3.connectionpool:https://<server>:443 "GET /api/v4/user HTTP/1.1" 200 None
reply: 'HTTP/1.1 200 OK\r\n'
header: Server: nginx
header: Date: Tue, 01 Feb 2022 14:41:20 GMT
header: Content-Type: application/json
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Vary: Accept-Encoding
header: Cache-Control: max-age=0, private, must-revalidate
header: Etag: W/"ed942cb0878d870e37b48a0aeaebf227"
header: Vary: Origin
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-Request-Id: 01FTTVQ955Z8DCZA35GXEXMFR3
header: X-Runtime: 0.409683
header: Strict-Transport-Security: max-age=63072000
header: Referrer-Policy: strict-origin-when-cross-origin
header: Content-Encoding: gzip
send: b'GET /api/v4/projects/22 HTTP/1.1\r\nHost: <server>\r\nUser-Agent: python-gitlab/3.1.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: <secret>\r\nContent-type: application/json\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Server: nginx
header: Date: Tue, 01 Feb 2022 14:41:21 GMT
header: Content-Type: application/json
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Vary: Accept-Encoding
header: Cache-Control: max-age=0, private, must-revalidate
header: Etag: W/"9fe17adcff0c6b14ac0649f0cd33e9ba"
header: Vary: Origin
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-Request-Id: 01FTTVQ9WJAV0P68PMXBHP2RTQ
header: X-Runtime: 0.192599
header: Strict-Transport-Security: max-age=63072000
header: Referrer-Policy: strict-origin-when-cross-origin
header: Content-Encoding: gzip
send: b'GET /api/v4/projects/22/issues HTTP/1.1\r\nHost: <server>\r\nUser-Agent: python-gitlab/3.1.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: <secret>\r\nContent-type: application/json\r\n\r\n'
DEBUG:urllib3.connectionpool:https://<server>:443 "GET /api/v4/projects/22 HTTP/1.1" 200 None
reply: 'HTTP/1.1 200 OK\r\n'
header: Server: nginx
header: Date: Tue, 01 Feb 2022 14:41:21 GMT
header: Content-Type: application/json
header: Content-Length: 2
header: Connection: keep-alive
header: Cache-Control: max-age=0, private, must-revalidate
header: Etag: W/"4f53cda18c2baa0c0354bb5f9a3ecbe5"
header: Link: <https://<server>/api/v4/projects/22/issues?id=22&order_by=created_at&page=1&per_page=20&sort=desc&state=all&with_labels_details=false>; rel="first", <https://<server>/api/v4/projects/22/issues?id=22&order_by=created_at&page=1&per_page=20&sort=desc&state=all&with_labels_details=false>; rel="last"
header: Vary: Origin
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-Next-Page: 
header: X-Page: 1
header: X-Per-Page: 20
header: X-Prev-Page: 
header: X-Request-Id: 01FTTVQA6ZGSY98Q9H8W5GW8EZ
header: X-Runtime: 0.054682
header: X-Total: 0
header: X-Total-Pages: 1
header: Strict-Transport-Security: max-age=63072000
header: Referrer-Policy: strict-origin-when-cross-origin
send: b'GET /api/v4/projects/22/labels HTTP/1.1\r\nHost: <server>\r\nUser-Agent: python-gitlab/3.1.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: <secret>\r\nContent-type: application/json\r\n\r\n'
DEBUG:urllib3.connectionpool:https://<server>:443 "GET /api/v4/projects/22/issues HTTP/1.1" 200 2
reply: 'HTTP/1.1 200 OK\r\n'
header: Server: nginx
header: Date: Tue, 01 Feb 2022 14:41:22 GMT
header: Content-Type: application/json
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Vary: Accept-Encoding
header: Cache-Control: max-age=0, private, must-revalidate
header: Etag: W/"2cd7c4d6f8251fb7843d09ba9152f7fe"
header: Link: <https://<server>/api/v4/projects/22/labels?id=22&include_ancestor_groups=true&page=2&per_page=20&with_counts=false>; rel="next", <https://<server>/api/v4/projects/22/labels?id=22&include_ancestor_groups=true&page=1&per_page=20&with_counts=false>; rel="first", <https://<server>/api/v4/projects/22/labels?id=22&include_ancestor_groups=true&page=2&per_page=20&with_counts=false>; rel="last"
header: Vary: Origin
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-Next-Page: 2
header: X-Page: 1
header: X-Per-Page: 20
header: X-Prev-Page: 
header: X-Request-Id: 01FTTVQAKJ6F92YZYDN77N1V2G
header: X-Runtime: 0.156185
header: X-Total: 34
header: X-Total-Pages: 2
header: Strict-Transport-Security: max-age=63072000
header: Referrer-Policy: strict-origin-when-cross-origin
header: Content-Encoding: gzip
send: b'GET /api/v4/projects/22/labels?id=22&include_ancestor_groups=true&page=2&per_page=20&with_counts=false HTTP/1.1\r\nHost: <server>\r\nUser-Agent: python-gitlab/3.1.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: <secret>\r\nContent-type: application/json\r\n\r\n'
DEBUG:urllib3.connectionpool:https://<server>:443 "GET /api/v4/projects/22/labels HTTP/1.1" 200 None
reply: 'HTTP/1.1 200 OK\r\n'
header: Server: nginx
header: Date: Tue, 01 Feb 2022 14:41:22 GMT
header: Content-Type: application/json
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Vary: Accept-Encoding
header: Cache-Control: max-age=0, private, must-revalidate
header: Etag: W/"d990a9de7b074a273384e76d34afc9a5"
header: Link: <https://<server>/api/v4/projects/22/labels?id=22&include_ancestor_groups=true&page=1&per_page=20&with_counts=false>; rel="prev", <https://<server>/api/v4/projects/22/labels?id=22&include_ancestor_groups=true&page=1&per_page=20&with_counts=false>; rel="first", <https://<server>/api/v4/projects/22/labels?id=22&include_ancestor_groups=true&page=2&per_page=20&with_counts=false>; rel="last"
header: Vary: Origin
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-Next-Page: 
header: X-Page: 2
header: X-Per-Page: 20
header: X-Prev-Page: 1
header: X-Request-Id: 01FTTVQAXQ1MZD57G4FCXEDKT9
header: X-Runtime: 0.103709
header: X-Total: 34
header: X-Total-Pages: 2
header: Strict-Transport-Security: max-age=63072000
header: Referrer-Policy: strict-origin-when-cross-origin
header: Content-Encoding: gzip
send: b'DELETE /api/v4/projects/22/labels?name=comp%253AFlat%2520Export HTTP/1.1\r\nHost: <server>\r\nUser-Agent: python-gitlab/3.1.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: <secret>\r\nContent-type: application/json\r\nContent-Length: 0\r\n\r\n'
DEBUG:urllib3.connectionpool:https://<server>:443 "GET /api/v4/projects/22/labels?id=22&include_ancestor_groups=true&page=2&per_page=20&with_counts=false HTTP/1.1" 200 None
reply: 'HTTP/1.1 404 Not Found\r\n'
header: Server: nginx
header: Date: Tue, 01 Feb 2022 14:41:22 GMT
header: Content-Type: application/json
header: Content-Length: 33
header: Connection: keep-alive
header: Cache-Control: no-cache
header: Vary: Origin
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-Request-Id: 01FTTVQB4XQMSFJ74JY3YAA7KB
header: X-Runtime: 0.145771
DEBUG:urllib3.connectionpool:https://<server>:443 "DELETE /api/v4/projects/22/labels?name=comp%253AFlat%2520Export HTTP/1.1" 404 33
Traceback (most recent call last):
  File "/Users/dirkmika/Documents/projects/jira2gitlab/venv/lib/python3.9/site-packages/gitlab/exceptions.py", line 311, in wrapped_f
    return f(*args, **kwargs)
  File "/Users/dirkmika/Documents/projects/jira2gitlab/venv/lib/python3.9/site-packages/gitlab/v4/objects/labels.py", line 183, in delete
    self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
  File "/Users/dirkmika/Documents/projects/jira2gitlab/venv/lib/python3.9/site-packages/gitlab/client.py", line 936, in http_delete
    return self.http_request("delete", path, **kwargs)
  File "/Users/dirkmika/Documents/projects/jira2gitlab/venv/lib/python3.9/site-packages/gitlab/client.py", line 727, in http_request
    raise gitlab.exceptions.GitlabHttpError(
gitlab.exceptions.GitlabHttpError: 404: 404 Label Not Found

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

Traceback (most recent call last):
  File "/Users/dirkmika/Library/Application Support/JetBrains/PyCharmCE2021.3/scratches/scratch_1.py", line 32, in <module>
    gl_label.delete()
  File "/Users/dirkmika/Documents/projects/jira2gitlab/venv/lib/python3.9/site-packages/gitlab/mixins.py", line 580, in delete
    self.manager.delete(self.encoded_id, **kwargs)
  File "/Users/dirkmika/Documents/projects/jira2gitlab/venv/lib/python3.9/site-packages/gitlab/exceptions.py", line 313, in wrapped_f
    raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabDeleteError: 404: 404 Label Not Found

Process finished with exit code 1

@JohnVillalovos
Copy link
Member

Seems like this is wrong:

send: b'DELETE /api/v4/projects/22/labels?name=comp%253AFlat%2520Export HTTP/1.1\r\nHost: <server>\r\nUser-Agent: python-gitlab/3.1.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: <secret>\r\nContent-type: application/json\r\nContent-Length: 0\r\n\r\n'
DEBUG:urllib3.connectionpool:https://<server>:443

Probably should be:

DELETE /api/v4/projects/22/labels/comp%253AFlat%2520Export

But also we probably have multiple encoding happening.

Python 3.10.2 (main, Jan 17 2022, 00:00:00) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.parse
>>> a ="comp%253AFlat%2520Export"
>>> urllib.parse.unquote(a)
'comp%3AFlat%20Export'
>>> b = urllib.parse.unquote(a)
>>> urllib.parse.unquote(b)
'comp:Flat Export'
>>>

@JohnVillalovos
Copy link
Member

@just-doit Any chance you can print the value of the label that you are trying to delete?

@just-doit
Copy link
Author

It's comp:Flat Export.

JohnVillalovos added a commit that referenced this issue Feb 1, 2022
The usage of deleting was incorrect according to the current API.

Closes: #1867
JohnVillalovos added a commit that referenced this issue Feb 1, 2022
The usage of deleting was incorrect according to the current API.

Add tests to show it works with labels needing to be encoded.

Also enable the test_group_labels() test function. Previously it was
disabled.

Closes: #1867
JohnVillalovos added a commit that referenced this issue Feb 1, 2022
The usage of deleting was incorrect according to the current API.
Remove custom `delete()` method as not needed.

Add tests to show it works with labels needing to be encoded.

Also enable the test_group_labels() test function. Previously it was
disabled.

Add ability to do a `get()` for group labels.

Closes: #1867
@JohnVillalovos
Copy link
Member

I have proposed a fix here: #1868

JohnVillalovos added a commit that referenced this issue Feb 1, 2022
The usage of deleting was incorrect according to the current API.
Remove custom `delete()` method as not needed.

Add tests to show it works with labels needing to be encoded.

Also enable the test_group_labels() test function. Previously it was
disabled.

Add ability to do a `get()` for group labels.

Closes: #1867
@just-doit
Copy link
Author

Wow this was fast. 👍

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants