Skip to content

ProjectFileManager does not implement head method to meet API spec #2976

Closed

Description

@holysoles

Description of the problem, including code/CLI snippet

Attempting to use a HEAD request to retrieve file metadata from a project repository (Gitlab REST API docs) fails with a 404

dest_file_get_args = {
  'file_path': file_def['dest_filepath'],
  'ref': 'HEAD',
}
existing_file = project.files.head(**dest_file_get_args)

Expected Behavior

Should return 200 and file metadata. The same request as a GET request returns 200, and they follow the same URL path and parameter requirements. Sending a GET request logs this URL path:

DEBUG:urllib3.connectionpool:https://gitlab.com:443 "GET /api/v4/projects/1/repository/files/somefile.txt?ref=HEAD HTTP/11" 200 418

Actual Behavior

A HTTP HEAD request is sent with the following URL path:
DEBUG:urllib3.connectionpool:https://gitlab.com:443 "HEAD /api/v4/projects/1/repository/files?file_path=somefile.txt&ref=HEAD HTTP/11" 404 0

Specifications

  • python-gitlab version: 3.1.43 4.9.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): v16.7.4-ee

Activity

  1. JohnVillalovos commented on Sep 11, 2024

    @JohnVillalovos
    Member

    That doesn't seem to be a HEAD request. It is a GET request that is asking for the ref called HEAD

  2. holysoles commented on Sep 11, 2024

    @holysoles
    ContributorAuthor

    @JohnVillalovos its a HEAD request asking for the HEAD ref. I can generate additional logs for other refs.

  3. holysoles commented on Sep 11, 2024

    @holysoles
    ContributorAuthor

    Working GET for master ref
    DEBUG:urllib3.connectionpool:https://gitlab.com:443 "GET /api/v4/projects/1/repository/files/somefile.txt?ref=master HTTP/11" 200 417

    Failing HEAD for master ref
    DEBUG:urllib3.connectionpool:https://gitlab.com:443 "HEAD /api/v4/projects/1/repository/files?file_path=somefile.txt&ref=master HTTP/11" 404 0

  4. holysoles commented on Sep 11, 2024

    @holysoles
    ContributorAuthor

    I'm pretty sure this is because GetMixin is inheriting HeadMixin and in ProjectFileManager we are overriding the get method, but that wouldn't override the default head method as far as I'm aware

  5. JohnVillalovos commented on Sep 11, 2024

    @JohnVillalovos
    Member

    As a note. Your python-gitlab version is fairly old.

    This almost seems like an issue with GitLab. But not sure. Would be interesting to try a curl test using both GET and HEAD. If only HEAD fails then something wrong with GitLab. If they both work then something happening with python-gitlab.

    Edit: Notice that the URLs set are slightly different. So pointing more toward python-gitlab

  6. nejch commented on Sep 11, 2024

    @nejch
    Member

    I think #2976 (comment) is right as you can see the file path gets passed as a query param unfortunately in the head() call. I guess we can't rely on this being consistent across the API endpoints.

  7. holysoles commented on Sep 11, 2024

    @holysoles
    ContributorAuthor

    @JohnVillalovos i can update my version and test again, but I've tested this commit and it works. Happy to open a PR if appropriate

    Wasnt sure if i should explicitly inherit HeadMixin or not in it.

  8. JohnVillalovos commented on Sep 11, 2024

    @JohnVillalovos
    Member

    @JohnVillalovos its a HEAD request asking for the HEAD ref. I can generate additional logs for other refs.

    Thanks. I was confused as original message had

    DEBUG:urllib3.connectionpool:[https://gitlab.com:443](https://gitlab.com/) "GET /api/v4/projects/1/repository/files/somefile.txt?ref=HEAD HTTP/11" 200 418
    
  9. holysoles commented on Sep 11, 2024

    @holysoles
    ContributorAuthor

    Also apologies, my version is 4.9.0, i grabbed the wrong dependency version from my requirements file

  10. JohnVillalovos commented on Sep 11, 2024

    @JohnVillalovos
    Member

    @JohnVillalovos i can update my version and test again, but I've tested this commit and it works. Happy to open a PR if appropriate

    Wasnt sure if i should explicitly inherit HeadMixin or not in it.

    PR sounds like a good idea. Thanks.

  11. nejch commented on Sep 11, 2024

    @nejch
    Member

    @JohnVillalovos @holysoles might also be a good idea to not inherit from GetMixin in that case if we're overriding it, to avoid this kind of confusion in the future. Not sure if there's any other implication there.

  12. holysoles commented on Sep 12, 2024

    @holysoles
    ContributorAuthor

    I should be able to get the PR opened tomorrow after I functionally test my update, but its passing unit tests

  13. locked as resolved and limited conversation to collaborators on Sep 15, 2025
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