Skip to content

Commit 0980a79

Browse files
mattgdclaude
andauthored
Fix outdated organization_membership events (#560)
* Fix outdated organization_membership events Default custom_attributes to empty dict and coerce null values from API to empty dict, ensuring type safety without requiring optional fields. Add event test for null custom_attributes deserialization. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * Remove null coercion; only handle undefined custom_attributes custom_attributes is never null from the API, only undefined. Remove the field_validator and null test, keep only the default and the missing-field test. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Format test_events.py with ruff Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 716622c commit 0980a79

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/workos/types/user_management/organization_membership.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any, Literal, Mapping, Optional, Sequence
2+
23
from typing_extensions import TypedDict
34

45
from workos.types.workos_model import WorkOSModel
@@ -21,6 +22,6 @@ class OrganizationMembership(WorkOSModel):
2122
role: OrganizationMembershipRole
2223
roles: Optional[Sequence[OrganizationMembershipRole]] = None
2324
status: LiteralOrUntyped[OrganizationMembershipStatus]
24-
custom_attributes: Mapping[str, Any]
25+
custom_attributes: Mapping[str, Any] = {}
2526
created_at: str
2627
updated_at: str

tests/test_events.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from tests.utils.fixtures.mock_event import MockEvent
55
from tests.utils.syncify import syncify
66
from workos.events import AsyncEvents, Events, EventsListResource
7+
from workos.types.events import OrganizationMembershipCreatedEvent
78

89

910
@pytest.mark.sync_and_async(Events, AsyncEvents)
@@ -40,3 +41,47 @@ def test_list_events(
4041
assert request_kwargs["method"] == "get"
4142
assert request_kwargs["params"] == {"events": ["dsync.activated"], "limit": 10}
4243
assert events.dict() == mock_events
44+
45+
def test_list_events_organization_membership_missing_custom_attributes(
46+
self,
47+
module_instance: Union[Events, AsyncEvents],
48+
capture_and_mock_http_client_request,
49+
):
50+
mock_response = {
51+
"object": "list",
52+
"data": [
53+
{
54+
"object": "event",
55+
"id": "event_01234",
56+
"event": "organization_membership.created",
57+
"data": {
58+
"object": "organization_membership",
59+
"id": "om_01234",
60+
"user_id": "user_01234",
61+
"organization_id": "org_01234",
62+
"role": {"slug": "member"},
63+
"status": "active",
64+
"created_at": "2024-01-01T00:00:00.000Z",
65+
"updated_at": "2024-01-01T00:00:00.000Z",
66+
},
67+
"created_at": "2024-01-01T00:00:00.000Z",
68+
}
69+
],
70+
"list_metadata": {
71+
"after": None,
72+
},
73+
}
74+
75+
capture_and_mock_http_client_request(
76+
http_client=module_instance._http_client,
77+
status_code=200,
78+
response_dict=mock_response,
79+
)
80+
81+
events: EventsListResource = syncify(
82+
module_instance.list_events(events=["organization_membership.created"])
83+
)
84+
85+
event = events.data[0]
86+
assert isinstance(event, OrganizationMembershipCreatedEvent)
87+
assert event.data.custom_attributes == {}

0 commit comments

Comments
 (0)