From deb04be0528b11d585cc62645b40702d6a67c220 Mon Sep 17 00:00:00 2001 From: Mohith26 <109003762+Mohith26@users.noreply.github.com> Date: Tue, 3 Nov 2026 00:18:03 -0500 Subject: [PATCH] Accept a single event type in user group audit filters types="MEMBER_ADDED" or types=UserGroupAuditEventType.MEMBER_ADDED was iterated one character at a time and failed with "'M' is not a valid UserGroupAuditEventType". Wrap a single string in a list, as the performance helpers already do for their types filter. --- libs/labelbox/src/labelbox/schema/user_group.py | 2 +- .../src/labelbox/schema/user_group_audit.py | 4 ++++ .../unit/schema/test_user_group_members_audit.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/labelbox/src/labelbox/schema/user_group.py b/libs/labelbox/src/labelbox/schema/user_group.py index be7dd63af..f60b00eb0 100644 --- a/libs/labelbox/src/labelbox/schema/user_group.py +++ b/libs/labelbox/src/labelbox/schema/user_group.py @@ -686,7 +686,7 @@ def get_audit_events( them. actor_kind: Only changes made by a person (``"PERSON"``), or only by automations (``"AUTOMATION"``). - types: Only these kinds of events. + types: Only these kinds of events: one type or a list of them. project: Only events of this project: a group attached to or detached from it. occurred_after: Only events at or after this moment. diff --git a/libs/labelbox/src/labelbox/schema/user_group_audit.py b/libs/labelbox/src/labelbox/schema/user_group_audit.py index c29267aaa..3441fdc51 100644 --- a/libs/labelbox/src/labelbox/schema/user_group_audit.py +++ b/libs/labelbox/src/labelbox/schema/user_group_audit.py @@ -210,6 +210,10 @@ def get_user_group_audit_events( before = _to_datetime("occurred_before", occurred_before) if after and before and after >= before: raise ValueError("occurred_after must be before occurred_before") + # A single type (a string or an enum member, which is also a string) + # would otherwise be iterated one character at a time. + if isinstance(types, str): + types = [types] where = { key: value for key, value in { diff --git a/libs/labelbox/tests/unit/schema/test_user_group_members_audit.py b/libs/labelbox/tests/unit/schema/test_user_group_members_audit.py index f9868986b..321fea794 100644 --- a/libs/labelbox/tests/unit/schema/test_user_group_members_audit.py +++ b/libs/labelbox/tests/unit/schema/test_user_group_members_audit.py @@ -285,6 +285,20 @@ def test_get_audit_events_without_group_and_unknown_values(self, client): "projectId": "project_1" } + @pytest.mark.parametrize( + "types", ["MEMBER_ADDED", UserGroupAuditEventType.MEMBER_ADDED] + ) + def test_accepts_a_single_type(self, group, client, types): + client.execute.return_value = { + "userGroupAuditEvents": {"nodes": [], "nextCursor": None} + } + + list(group.audit_events(types=types)) + + assert client.execute.call_args[0][1]["where"]["types"] == [ + "MEMBER_ADDED" + ] + def test_rejects_bad_filters(self, group, client): with pytest.raises(ValueError): group.audit_events(actor_kind="ROBOT")