FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Deleting a label fails with 404 · Issue #1867 · python-gitlab/python-gitlab · GitHub

Repository navigation

Deleting a label fails with 404 #1867

Description

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

Activity

  1. nejch commented on Feb 1, 2022

    Member

    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.

  2. just-doit commented on Feb 1, 2022

    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
  3. JohnVillalovos commented on Feb 1, 2022

    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'
    >>>
    
  4. JohnVillalovos commented on Feb 1, 2022

    Member

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

  5. just-doit commented on Feb 1, 2022

    Author

    It's comp:Flat Export.

  6. added 3 commits that reference this issue on Feb 1, 2022
    05ff81d
    3870af8
    9c0d7a7
  7. JohnVillalovos commented on Feb 1, 2022

    Member

    I have proposed a fix here: #1868

  8. added a commit that references this issue on Feb 1, 2022
    0841a2a
  9. just-doit commented on Feb 1, 2022

    Author

    Wow this was fast. 👍

  10. locked as resolved and limited conversation to collaborators on Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL