Skip to content

Commit 2d51bec

Browse files
gjtorikianclaude
andcommitted
chore(python): regenerate SDK with exceptions and types backwards-compat
Restores `from workos.exceptions import ...` and `from workos.types.<service> import ...` import paths. Updates V6 migration guide to remove these as breaking changes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f1f0d8f commit 2d51bec

File tree

47 files changed

+437
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+437
-132
lines changed

docs/V6_MIGRATION_GUIDE.md

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Read this as the migration guide for the generated-surface major release, not as
1515
- [Python 3.10+ is now required](#python-310-is-now-required)
1616
- [`client_id` is only required for flows that use it](#client_id-is-only-required-for-flows-that-use-it)
1717
- [Legacy client modules were removed](#legacy-client-modules-were-removed)
18-
- [SDK exceptions now come from `workos`, not `workos.exceptions`](#sdk-exceptions-now-come-from-workos-not-workosexceptions)
19-
- [Models no longer live under `workos.types.*`](#models-no-longer-live-under-workostypes)
2018
- [SDK models are no longer Pydantic models](#sdk-models-are-no-longer-pydantic-models)
2119
- [`client.connect` was split into explicit resources](#clientconnect-was-split-into-explicit-resources)
2220
- [`client.directory_sync` was split into directories, groups, and users](#clientdirectory_sync-was-split-into-directories-groups-and-users)
@@ -36,7 +34,7 @@ Read this as the migration guide for the generated-surface major release, not as
3634

3735
1. Upgrade to Python 3.10 or newer.
3836
2. Update to the v6 release.
39-
3. Replace legacy imports from `workos.client`, `workos.async_client`, `workos.exceptions`, and `workos.types.*`.
37+
3. Replace legacy imports from `workos.client` and `workos.async_client`.
4038
4. Update any uses of `connect`, `portal`, `directory_sync`, `fga`, `authorization` permission helpers, and old `user_management` convenience helpers.
4139
5. Run your tests and look specifically for import errors, missing methods, and model serialization issues.
4240

@@ -105,52 +103,6 @@ client = WorkOSClient(api_key="sk_test_123", client_id="client_123")
105103
**Affected users:** Anyone importing `SyncClient`, `AsyncClient`, or other client classes from legacy client modules
106104
**Migration:** Import clients from the top-level `workos` package instead of `workos.client` or `workos.async_client`
107105

108-
### SDK exceptions now come from `workos`, not `workos.exceptions`
109-
110-
**5.x (old):**
111-
112-
```python
113-
from workos.exceptions import BaseRequestException
114-
115-
try:
116-
client.organizations.get_organization("org_123")
117-
except BaseRequestException as exc:
118-
print(exc.request_id)
119-
```
120-
121-
**6.x (new):**
122-
123-
```python
124-
from workos import BaseRequestException
125-
126-
try:
127-
client.organizations.get("org_123")
128-
except BaseRequestException as exc:
129-
print(exc.request_id)
130-
```
131-
132-
**Affected users:** Anyone importing exception classes from `workos.exceptions`
133-
**Migration:** Import exception classes directly from `workos`
134-
135-
### Models no longer live under `workos.types.*`
136-
137-
**5.x (old):**
138-
139-
```python
140-
from workos.types.organizations import Organization
141-
from workos.types.connect import ConnectApplication
142-
```
143-
144-
**6.x (new):**
145-
146-
```python
147-
from workos.organizations.models import Organization
148-
from workos.applications.models import ConnectApplication
149-
```
150-
151-
**Affected users:** Anyone importing SDK models from `workos.types.*`
152-
**Migration:** Import models from the generated `workos.<resource>.models` packages
153-
154106
### SDK models are no longer Pydantic models
155107

156108
**5.x (old):**
@@ -456,7 +408,7 @@ organization = client.organizations.get("org_123")
456408

457409
1. Upgrade Python to 3.10+.
458410
2. Review which flows need `client_id` and either pass it explicitly or configure it on the client / environment.
459-
3. Fix imports from `workos.client`, `workos.async_client`, `workos.exceptions`, and `workos.types.*`.
411+
3. Fix imports from `workos.client` and `workos.async_client`.
460412
4. Replace old namespaces: `connect`, `directory_sync`, `portal`, `fga`, and handwritten `user_management` helpers.
461413
5. Move permission CRUD from `client.authorization` to `client.permissions`.
462414
6. Update model serialization code away from Pydantic helpers.
@@ -466,8 +418,6 @@ organization = client.organizations.get("org_123")
466418

467419
- No imports from `workos.client`
468420
- No imports from `workos.async_client`
469-
- No imports from `workos.exceptions`
470-
- No imports from `workos.types.*`
471421
- Client-ID-based flows explicitly pass `client_id` or configure it on the client / environment
472422
- No remaining uses of `client.connect`
473423
- No remaining uses of `client.directory_sync`

src/workos/audit_logs/models/audit_log_action_json.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class AuditLogActionJson:
2020
name: str
2121
"""Identifier of what action was taken."""
2222
schema: "AuditLogSchemaJson"
23+
"""The schema associated with the action."""
2324
created_at: datetime
2425
"""An ISO 8601 timestamp."""
2526
updated_at: datetime

src/workos/audit_logs/models/audit_log_schema_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@dataclass(slots=True)
1616
class AuditLogSchemaJson:
17-
"""The schema associated with the action."""
17+
"""Audit Log Schema Json model."""
1818

1919
object: Literal["audit_log_schema"]
2020
"""Distinguishes the Audit Log Schema object."""

src/workos/authorization/models/role_assignment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class RoleAssignment:
2121
id: str
2222
"""Unique identifier of the role assignment."""
2323
role: "SlimRole"
24+
"""The role included in the assignment."""
2425
resource: "RoleAssignmentResource"
2526
"""The resource to which the role is assigned."""
2627
created_at: datetime

src/workos/authorization/models/slim_role.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@dataclass(slots=True)
1111
class SlimRole:
12-
"""The role included in the assignment."""
12+
"""The primary role assigned to the user."""
1313

1414
slug: str
1515
"""The slug of the assigned role."""

src/workos/directory_users/models/directory_user_with_groups.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class DirectoryUserWithGroups:
5353
username: Optional[str] = None
5454
"""The username of the user."""
5555
role: Optional["SlimRole"] = None
56-
"""The primary role assigned to the user."""
5756
roles: Optional[List["SlimRole"]] = None
5857
"""All roles assigned to the user."""
5958

src/workos/events/_resource.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .._client import AsyncWorkOSClient, WorkOSClient
99

1010
from .._types import RequestOptions, enum_value
11-
from .models import Event
11+
from .models import EventSchema
1212
from .models import EventsOrder
1313
from .._pagination import AsyncPage, SyncPage
1414

@@ -31,7 +31,7 @@ def list(
3131
range_end: Optional[str] = None,
3232
organization_id: Optional[str] = None,
3333
request_options: Optional[RequestOptions] = None,
34-
) -> SyncPage[Event]:
34+
) -> SyncPage[EventSchema]:
3535
"""List events
3636
3737
List events for the current environment.
@@ -48,7 +48,7 @@ def list(
4848
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.
4949
5050
Returns:
51-
SyncPage[Event]
51+
SyncPage[EventSchema]
5252
5353
Raises:
5454
BadRequestException: If the request is malformed (400).
@@ -74,7 +74,7 @@ def list(
7474
return self._client.request_page(
7575
method="get",
7676
path="events",
77-
model=Event,
77+
model=EventSchema,
7878
params=params,
7979
request_options=request_options,
8080
)
@@ -98,7 +98,7 @@ async def list(
9898
range_end: Optional[str] = None,
9999
organization_id: Optional[str] = None,
100100
request_options: Optional[RequestOptions] = None,
101-
) -> AsyncPage[Event]:
101+
) -> AsyncPage[EventSchema]:
102102
"""List events
103103
104104
List events for the current environment.
@@ -115,7 +115,7 @@ async def list(
115115
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.
116116
117117
Returns:
118-
AsyncPage[Event]
118+
AsyncPage[EventSchema]
119119
120120
Raises:
121121
BadRequestException: If the request is malformed (400).
@@ -141,7 +141,7 @@ async def list(
141141
return await self._client.request_page(
142142
method="get",
143143
path="events",
144-
model=Event,
144+
model=EventSchema,
145145
params=params,
146146
request_options=request_options,
147147
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# This file is auto-generated by oagen. Do not edit.
22

3-
from .event import Event as Event
3+
from .event_schema import EventSchema as EventSchema
44
from .events_order import EventsOrder as EventsOrder
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This file is auto-generated by oagen. Do not edit.
2+
3+
from __future__ import annotations
4+
5+
from dataclasses import dataclass
6+
from datetime import datetime
7+
from typing import Any, Dict, Literal, Optional
8+
from workos._errors import BaseRequestException
9+
10+
11+
@dataclass(slots=True)
12+
class EventSchema:
13+
"""An event emitted by WorkOS."""
14+
15+
object: Literal["event"]
16+
"""Distinguishes the Event object."""
17+
id: str
18+
"""Unique identifier for the Event."""
19+
event: str
20+
"""The type of event that occurred."""
21+
data: Dict[str, Any]
22+
"""The event payload."""
23+
created_at: datetime
24+
"""An ISO 8601 timestamp."""
25+
context: Optional[Dict[str, Any]] = None
26+
"""Additional context about the event."""
27+
28+
@classmethod
29+
def from_dict(cls, data: Dict[str, Any]) -> "EventSchema":
30+
"""Deserialize from a dictionary."""
31+
try:
32+
return cls(
33+
object=data["object"],
34+
id=data["id"],
35+
event=data["event"],
36+
data=data["data"],
37+
created_at=datetime.fromisoformat(
38+
data["created_at"].replace("Z", "+00:00")
39+
),
40+
context=data.get("context"),
41+
)
42+
except (KeyError, ValueError) as e:
43+
raise BaseRequestException(
44+
f"Unexpected API response while parsing EventSchema: {e!s}"
45+
) from e
46+
47+
def to_dict(self) -> Dict[str, Any]:
48+
"""Serialize to a dictionary."""
49+
result: Dict[str, Any] = {}
50+
result["object"] = self.object
51+
result["id"] = self.id
52+
result["event"] = self.event
53+
result["data"] = self.data
54+
result["created_at"] = self.created_at.isoformat(
55+
timespec="milliseconds"
56+
).replace("+00:00", "Z")
57+
if self.context is not None:
58+
result["context"] = self.context
59+
return result

src/workos/exceptions.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This file is auto-generated by oagen. Do not edit.
2+
3+
"""Backwards-compatible re-export of exception classes.
4+
5+
Allows 'from workos.exceptions import ...' alongside the
6+
canonical 'from workos import ...' path.
7+
"""
8+
9+
from ._errors import (
10+
BaseRequestException as BaseRequestException,
11+
AuthenticationException as AuthenticationException,
12+
AuthorizationException as AuthorizationException,
13+
BadRequestException as BadRequestException,
14+
ConflictException as ConflictException,
15+
ConfigurationException as ConfigurationException,
16+
EmailVerificationRequiredException as EmailVerificationRequiredException,
17+
NotFoundException as NotFoundException,
18+
RateLimitExceededException as RateLimitExceededException,
19+
ServerException as ServerException,
20+
UnprocessableEntityException as UnprocessableEntityException,
21+
WorkOSConnectionException as WorkOSConnectionException,
22+
WorkOSTimeoutException as WorkOSTimeoutException,
23+
STATUS_CODE_TO_EXCEPTION as STATUS_CODE_TO_EXCEPTION,
24+
)
25+
26+
__all__ = [
27+
"BaseRequestException",
28+
"AuthenticationException",
29+
"AuthorizationException",
30+
"BadRequestException",
31+
"ConflictException",
32+
"ConfigurationException",
33+
"EmailVerificationRequiredException",
34+
"NotFoundException",
35+
"RateLimitExceededException",
36+
"ServerException",
37+
"UnprocessableEntityException",
38+
"WorkOSConnectionException",
39+
"WorkOSTimeoutException",
40+
"STATUS_CODE_TO_EXCEPTION",
41+
]

0 commit comments

Comments
 (0)