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

CLI: gitlab user-project list doesn't work · Issue #2558 · python-gitlab/python-gitlab · GitHub

Repository navigation

CLI: gitlab user-project list doesn't work #2558

Description

Description of the problem, including code/CLI snippet

gitlab user-project list --user-id 42 fails.

A similar issue has previously been reported in #881 .

Expected Behavior

List of projects owned by the current user are shown.

Actual Behavior

Impossible to list objects ('user_id') is printed.

Specifications

  • python-gitlab version: 3.14.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): GitLab Community Edition 15.11.0

Notes

So I solved my particular problem by hard-coding my user-id in gitlab/v4/objects/user.py l. 641 (in the UserProjectManager list method). Obviously not a general solution, but maybe it helps to track down the error or someone else who comes across this. :)

Furthermore, what I really don't understand is why no KeyError is raised when the format string is processed.

Activity

  1. nejch commented on May 1, 2023

    Member

    Looks like a regression from ac1c619, as we started deleting kwargs for other reasons, so by the time we're doing do_list() in the CLI the user_id is already gone.

  2. w7089 commented on May 3, 2023

    It's interesting that there's no issue with API, only with CLI.

    Below code

    user = gl.users.get(3)
    print(user.projects.list())
    

    gets and prints the project list without any issue.

  3. nejch commented on May 3, 2023

    Member

    @w7089 it's mostly because of how the CLI constructs the methods called. Some arguments get passed around in run() and get cleaned up erroneously in this case because we use a custom method that expects the arguments used a little differently from our normal mixins.

  4. w7089 commented on May 24, 2023

    @nejch I believe the fix is as simple as adding self.mgr._from_parent_attrs = self.parent_args here. I tried locally and the issue got resolved.

    If it's acceptable, i'll open a PR after testing of other managers.

    I may be wrong as well and miss something as it's my first ever PR here.

  5. JohnVillalovos commented on May 28, 2023

    Member

    If it's acceptable, i'll open a PR after testing of other managers.

    Please feel free to open a PR if you think you have a valid fix. Thanks.

  6. JohnVillalovos commented on May 28, 2023

    Member

    I think the main reason for this is because of UserProjectManager and the fact that the path has to be regenerated.

    class UserProjectManager(ListMixin, CreateMixin, RESTManager):
    _path = "/projects/user/{user_id}"
    _obj_cls = UserProject
    _from_parent_attrs = {"user_id": "id"}
    _create_attrs = RequiredOptional(
    required=("name",),
    optional=(
    "default_branch",
    "issues_enabled",
    "wall_enabled",
    "merge_requests_enabled",
    "wiki_enabled",
    "snippets_enabled",
    "squash_option",
    "public",
    "visibility",
    "description",
    "builds_enabled",
    "public_builds",
    "import_url",
    "only_allow_merge_if_build_succeeds",
    ),
    )
    _list_filters = (
    "archived",
    "visibility",
    "order_by",
    "sort",
    "search",
    "simple",
    "owned",
    "membership",
    "starred",
    "statistics",
    "with_issues_enabled",
    "with_merge_requests_enabled",
    "with_custom_attributes",
    "with_programming_language",
    "wiki_checksum_failed",
    "repository_checksum_failed",
    "min_access_level",
    "id_after",
    "id_before",
    )
    def list(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]:
    """Retrieve a list of objects.
    Args:
    all: If True, return all the items, without pagination
    per_page: Number of items to retrieve per request
    page: ID of the page to return (starts with page 1)
    iterator: If set to True and no pagination option is
    defined, return a generator instead of a list
    **kwargs: Extra options to send to the server (e.g. sudo)
    Returns:
    The list of objects, or a generator if `iterator` is True
    Raises:
    GitlabAuthenticationError: If authentication is not correct
    GitlabListError: If the server cannot perform the request
    """
    if self._parent:
    path = f"/users/{self._parent.id}/projects"
    else:
    path = f"/users/{kwargs['user_id']}/projects"

    So maybe the idea of setting the parent attributes is correct but I'm not sure.

  7. w7089 commented on May 31, 2023

    ok, opened the pull request, 2 previous PRs can be deleted, they are not relevant.

  8. w7089 commented on Jun 30, 2023

    @JohnVillalovos any feedback on the PR?

  9. JohnVillalovos commented on Jul 6, 2023

    Member

    @JohnVillalovos any feedback on the PR?

    I'll try to look at it this week. Sorry for the delay.

  10. locked as resolved and limited conversation to collaborators on Oct 14, 2024
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

    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