Skip to content

Commit dc2e04a

Browse files
mattgdclaude
andcommitted
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>
1 parent aa575ec commit dc2e04a

File tree

2 files changed

+27
-39
lines changed

2 files changed

+27
-39
lines changed

src/workos/types/user_management/organization_membership.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Any, Literal, Mapping, Optional, Sequence
22

3-
from pydantic import field_validator
43
from typing_extensions import TypedDict
54

65
from workos.types.workos_model import WorkOSModel
@@ -26,10 +25,3 @@ class OrganizationMembership(WorkOSModel):
2625
custom_attributes: Mapping[str, Any] = {}
2726
created_at: str
2827
updated_at: str
29-
30-
@field_validator("custom_attributes", mode="before")
31-
@classmethod
32-
def _coerce_null_custom_attributes(cls, v: Any) -> Any:
33-
if v is None:
34-
return {}
35-
return v

tests/test_events.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,6 @@ def mock_events(self):
2121
},
2222
}
2323

24-
@pytest.fixture
25-
def mock_organization_membership_event_with_null_custom_attributes(self):
26-
return {
27-
"object": "list",
28-
"data": [
29-
{
30-
"object": "event",
31-
"id": "event_01234",
32-
"event": "organization_membership.created",
33-
"data": {
34-
"object": "organization_membership",
35-
"id": "om_01234",
36-
"user_id": "user_01234",
37-
"organization_id": "org_01234",
38-
"role": {"slug": "member"},
39-
"status": "active",
40-
"custom_attributes": None,
41-
"created_at": "2024-01-01T00:00:00.000Z",
42-
"updated_at": "2024-01-01T00:00:00.000Z",
43-
},
44-
"created_at": "2024-01-01T00:00:00.000Z",
45-
}
46-
],
47-
"list_metadata": {
48-
"after": None,
49-
},
50-
}
51-
5224
def test_list_events(
5325
self,
5426
module_instance: Union[Events, AsyncEvents],
@@ -70,16 +42,40 @@ def test_list_events(
7042
assert request_kwargs["params"] == {"events": ["dsync.activated"], "limit": 10}
7143
assert events.dict() == mock_events
7244

73-
def test_list_events_organization_membership_null_custom_attributes(
45+
def test_list_events_organization_membership_missing_custom_attributes(
7446
self,
7547
module_instance: Union[Events, AsyncEvents],
76-
mock_organization_membership_event_with_null_custom_attributes,
7748
capture_and_mock_http_client_request,
7849
):
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+
7975
capture_and_mock_http_client_request(
8076
http_client=module_instance._http_client,
8177
status_code=200,
82-
response_dict=mock_organization_membership_event_with_null_custom_attributes,
78+
response_dict=mock_response,
8379
)
8480

8581
events: EventsListResource = syncify(

0 commit comments

Comments
 (0)