Skip to content

[PLT-2655] Update UserGroup for V3 APIs #1986

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

Merged
merged 7 commits into from
Jun 13, 2025

Conversation

paulnoirel
Copy link
Contributor

@paulnoirel paulnoirel commented Jun 12, 2025

Description

PLT-2655
To resolve the problems with group memberships encountered when using UserGroup, methods have been updated to utilise V3 APIs.

Changes

Create

Legacy mode

import labelbox as lb
from labelbox.schema.user_group import UserGroup, UserGroupColor, UserGroupMember
API_KEY = "<API_KEY>"

client = lb.Client(API_KEY)
roles = client.get_roles()

users = (u for u in client.get_users() if u.org_role().name == 'None') # Filter on project-based users
projects = client.get_projects()

user_group_with_roles = UserGroup(
    client=client,
    name="User Group with Explicit Roles",
    color=UserGroupColor.GREEN,
    users={next(users), next(users), next(users)},
    default_role=roles["REVIEWER"],
    projects={next(projects)},
    description="Legacy test"
)
created_group_with_roles = user_group_with_roles.create()

New attribute: members

Note: members takes precedence over users if used simultaneously.

import labelbox as lb
from labelbox.schema.user_group import UserGroup, UserGroupColor, UserGroupMember
API_KEY = "<API_KEY>"

client = lb.Client(API_KEY)
roles = client.get_roles()

users = (u for u in client.get_users() if u.org_role().name == 'None')
projects = client.get_projects()

user_group_with_roles = UserGroup(
    client=client,
    name="User Group with Explicit Roles",
    color=UserGroupColor.GREEN,
    members={
        UserGroupMember(user=next(users), role=roles["LABELER"]),
        UserGroupMember(user=next(users), role=roles["REVIEWER"]),
        UserGroupMember(user=next(users), role=roles["LABELER"])
    },
    projects={next(projects)},
    description="Basic test"
)
created_group_with_roles = user_group_with_roles.create()

Update

created_group_with_roles.default_role = roles["PROJECT_LEAD"]
created_group_with_roles.users.add(next(users))

created_group_with_roles.members.add(UserGroupMember(next(users), roles["TEAM_MANAGER"]))

created_group_with_roles.projects.add(next(projects))

created_group_with_roles.description = "New group"

created_group_with_roles.update()

Delete

created_group_with_roles.delete()

Fixes # PLT-2655

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Document change (fix typo or modifying any markdown files, code comments or anything in the examples folder only)

All Submissions

  • Have you followed the guidelines in our Contributing document?
  • Have you provided a description?
  • Are your changes properly formatted?

New Feature Submissions

  • Does your submission pass tests?
  • Have you added thorough tests for your new feature?
  • Have you commented your code, particularly in hard-to-understand areas?
  • Have you added a Docstring?

Changes to Core Features

  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you updated any code comments, as applicable?

@paulnoirel paulnoirel force-pushed the pno/PLT-2655-fix-user-group branch from b04eb53 to d2ebd76 Compare June 12, 2025 21:34
@paulnoirel paulnoirel marked this pull request as ready for review June 13, 2025 00:38
Comment on lines +124 to +125
users: Legacy set of users (maintained for backward compatibility).
members: Set of UserGroupMember objects with explicit roles.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also ensure that either users or members is used but not both?

@paulnoirel paulnoirel merged commit d50b9d1 into develop Jun 13, 2025
43 of 45 checks passed
@paulnoirel paulnoirel deleted the pno/PLT-2655-fix-user-group branch June 13, 2025 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants