Skip to content

ldap_group_links.list() not usable #2738

Closed as not planned
Closed as not planned

Description

@zapp42

Description of the problem, including code/CLI snippet

The current implementation of the list() method for the ldap_group_links api is not usable. The cli throws an exceptions and the api returns unusable data, because an id is missing.

$ gitlab group-ldap-group-link list --group-id xxxxxx
[, , , , , , ]
Traceback (most recent call last):
File "/home/rof/.local/bin/gitlab", line 8, in
sys.exit(main())
^^^^^^
File "/home/rof/.local/lib/python3.12/site-packages/gitlab/cli.py", line 389, in main
gitlab.v4.cli.run(
File "/home/rof/.local/lib/python3.12/site-packages/gitlab/v4/cli.py", line 556, in run
printer.display_list(data, fields, verbose=verbose)
File "/home/rof/.local/lib/python3.12/site-packages/gitlab/v4/cli.py", line 518, in display_list
self.display(get_dict(obj, fields), verbose=verbose, obj=obj)
File "/home/rof/.local/lib/python3.12/site-packages/gitlab/v4/cli.py", line 487, in display
id = getattr(obj, obj._id_attr)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rof/.local/lib/python3.12/site-packages/gitlab/base.py", line 134, in getattr
raise AttributeError(message)
AttributeError: 'GroupLDAPGroupLink' object has no attribute 'id'

I think the problem is, that the ldap_group_links api has two possible (exclusive) id fields: cn and filter. I did not find a way to reflect this in python-gitlab. As we do not use ldap filters in our Gitlab instance, my "fix" was to add

_id_attr = "cn"

to the GroupLDAPGroupLink class.

Expected Behavior

The data returned shall contain either a cn or filter field.

Actual Behavior

Returned data only has the provider attribute, which is useless without the other field(s).

Specifications

  • python-gitlab version: 4.2.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 16.5.3

Activity

  1. zapp42 commented on Dec 4, 2023

    @zapp42
    Author

    Sorry, the output was stripped, it looks like this:

    [<GroupLDAPGroupLink id:None provider:ldapmain>, <GroupLDAPGroupLink id:None provider:ldapmain>, <GroupLDAPGroupLink id:None provider:ldapmain>, <GroupLDAPGroupLink id:None provider:ldapmain>, <GroupLDAPGroupLink id:None provider:ldapmain>, <GroupLDAPGroupLink id:None provider:ldapmain>, <GroupLDAPGroupLink id:None provider:ldapmain>]
    
  2. zapp42 commented on Dec 4, 2023

    @zapp42
    Author

    The create cli method is also not usable, as it does not accept a cn or filter parameter, one of those is required.

    The delete cli method expects a cn parameter, but no provider. This api is deprecated. The current one also requires a provider and either cn or filter.
    https://docs.gitlab.com/ee/api/groups.html#delete-ldap-group-link

    Shall I create separate issues for that or broaden the scope of this one?

  3. nejch commented on Dec 12, 2023

    @nejch
    Member

    Thanks @zapp42, I'll admit the maintainers here never had a use case for this and the new methods were just a port of the old deprecated ones.

    I'd be happy to review a PR or look at this at a later stage since it's a Premium features and thus not really on our radar so much.

  4. Sjord commented on Jan 21, 2024

    @Sjord
    Contributor

    gitlab group-ldap-group-link list --group-id xxxxxx performs a request to /api/v4/groups/xxxxxx/ldap_group_links, and the response looks like this:

    [{"cn":"foo","group_access":10,"provider":"ldap"}]
    
  5. Sjord commented on Jan 21, 2024

    @Sjord
    Contributor

    Setting _id_attr = None would at least get rid of the exception, and then --verbose can be used to also display the cn or filter fields.

    Since _id_attr is a class property and not an object property, it is not really possible to change it depending on whether an object has a filter or cn property.

  6. github-actions commented on Jul 9, 2025

    @github-actions

    This issue was marked stale because it has been open 60 days with
    no activity. Please remove the stale label or comment on this
    issue. Otherwise, it will be closed in 15 days.

    As an open-source project, we rely on community contributions to
    address many of the reported issues. Without a proposed fix or
    active work towards a solution it is our policy to close inactive
    issues. This is documented in CONTRIBUTING.rst

    How to keep this issue open:

    • If you are still experiencing this issue and are willing to
      investigate a fix, please comment and let us know.
    • If you (or someone else) can propose a pull request with a
      solution, that would be fantastic.
    • Any significant update or active discussion indicating progress
      will also prevent closure.

    We value your input. If you can help provide a fix, we'd be happy
    to keep this issue open and support your efforts.

    This is documented in CONTRIBUTING.rst
    https://github.com/python-gitlab/python-gitlab/blob/main/CONTRIBUTING.rst

  7. github-actions commented on Jul 24, 2025

    @github-actions

    This issue was closed because it has been marked stale for 15 days
    with no activity.

    This open-source project relies on community contributions, and
    while we value all feedback, we have a limited capacity to address
    every issue without a clear path forward.

    Currently, this issue hasn't received a proposed fix, and there
    hasn't been recent active discussion indicating someone is planning
    to work on it. To maintain a manageable backlog and focus our
    efforts, we will be closing this issue for now.

    This doesn't mean the issue isn't valid or important. If you or
    anyone else in the community is willing to investigate and propose
    a solution (e.g., by submitting a pull request), please do.

    We believe that those who feel a bug is important enough to fix
    should ideally be part of the solution. Your contributions are
    highly welcome.

    Thank you for your understanding and potential future
    contributions.

    This is documented in CONTRIBUTING.rst
    https://github.com/python-gitlab/python-gitlab/blob/main/CONTRIBUTING.rst

  8. locked as resolved and limited conversation to collaborators on Aug 3, 2026
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