Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Literal, Mapping, Optional, Sequence

from typing_extensions import TypedDict

from workos.types.workos_model import WorkOSModel
Expand All @@ -21,6 +22,6 @@ class OrganizationMembership(WorkOSModel):
role: OrganizationMembershipRole
roles: Optional[Sequence[OrganizationMembershipRole]] = None
status: LiteralOrUntyped[OrganizationMembershipStatus]
custom_attributes: Mapping[str, Any]
custom_attributes: Mapping[str, Any] = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This handles cases for events from before the IdP attributes in AuthKit release where custom_attributes is undefined.

created_at: str
updated_at: str
45 changes: 45 additions & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tests.utils.fixtures.mock_event import MockEvent
from tests.utils.syncify import syncify
from workos.events import AsyncEvents, Events, EventsListResource
from workos.types.events import OrganizationMembershipCreatedEvent


@pytest.mark.sync_and_async(Events, AsyncEvents)
Expand Down Expand Up @@ -40,3 +41,47 @@ def test_list_events(
assert request_kwargs["method"] == "get"
assert request_kwargs["params"] == {"events": ["dsync.activated"], "limit": 10}
assert events.dict() == mock_events

def test_list_events_organization_membership_missing_custom_attributes(
self,
module_instance: Union[Events, AsyncEvents],
capture_and_mock_http_client_request,
):
mock_response = {
"object": "list",
"data": [
{
"object": "event",
"id": "event_01234",
"event": "organization_membership.created",
"data": {
"object": "organization_membership",
"id": "om_01234",
"user_id": "user_01234",
"organization_id": "org_01234",
"role": {"slug": "member"},
"status": "active",
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z",
},
"created_at": "2024-01-01T00:00:00.000Z",
}
],
"list_metadata": {
"after": None,
},
}

capture_and_mock_http_client_request(
http_client=module_instance._http_client,
status_code=200,
response_dict=mock_response,
)

events: EventsListResource = syncify(
module_instance.list_events(events=["organization_membership.created"])
)

event = events.data[0]
assert isinstance(event, OrganizationMembershipCreatedEvent)
assert event.data.custom_attributes == {}