Skip to content

Conversation

@gjtorikian
Copy link
Contributor

Description

The provided parameters were not matching the actual parameters the API was expecting.

Closes #511.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@gjtorikian gjtorikian requested a review from a team as a code owner January 13, 2026 19:48
@gjtorikian gjtorikian requested a review from gcarvelli January 13, 2026 19:48
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 13, 2026

Greptile Summary

This PR attempts to fix issue #511 by changing the API parameter names from directory/group/user to directory_id/group_id/user_id in both sync and async implementations of list_users and list_groups methods.

Critical Issue: This change is incorrect and will break all API calls. The WorkOS API expects parameters without the _id suffix:

  • Type definitions in src/workos/types/directory_sync/list_filters.py define directory: Optional[str], group: Optional[str], and user: Optional[str] (lines 15-21)
  • Existing tests verify API calls use "directory", "group", and "user" parameters (see tests/test_directory_sync.py lines 148, 166, 184, 202)
  • The tests will fail with this change as they explicitly check for parameter names without _id

Root Cause Analysis: The error in issue #511 (TypeError: DirectorySync.list_groups() got an unexpected keyword argument 'directory') is misleading. The actual problem is a mismatch where:

  • Function signatures accept directory_id, group_id, user_id as parameters (correct for Python API)
  • But the type definitions expect directory, group, user (correct for HTTP API)
  • The implementation was correctly translating from function parameters to API parameters

Correct Fix: The type definitions in list_filters.py should be updated to use directory_id, group_id, and user_id to properly match the function signatures, while keeping the HTTP parameter names as they were.

Confidence Score: 0/5

  • This PR is unsafe to merge and will break all directory sync API calls
  • The changes directly contradict the type definitions and existing tests. All four modified methods will send incorrect parameter names to the WorkOS API, causing all list_users and list_groups calls to fail. The tests at tests/test_directory_sync.py explicitly verify that parameters should be sent as directory, group, and user without the _id suffix.
  • Pay critical attention to src/workos/directory_sync.py - all parameter mappings are incorrect and need to be reverted

Important Files Changed

Filename Overview
src/workos/directory_sync.py Changed API parameter names from directory/group/user to directory_id/group_id/user_id, but this breaks compatibility with the actual WorkOS API which expects parameters without _id suffix

Sequence Diagram

sequenceDiagram
    participant User
    participant SDK as DirectorySync
    participant Types as DirectoryUserListFilters
    participant API as WorkOS API

    User->>SDK: list_users(directory_id="dir_123")
    Note over SDK: Function signature accepts directory_id
    
    SDK->>Types: Create list_params dict
    Note over SDK,Types: ISSUE: PR changes this to use directory_id
    SDK->>Types: list_params["directory_id"] = "dir_123" ❌
    Note over Types: Type expects "directory" key (no _id)
    
    SDK->>API: GET /directory_users?directory_id=dir_123
    Note over API: API expects "directory" not "directory_id"
    API-->>SDK: Error: Unknown parameter
    SDK-->>User: API Error
    
    Note over User,API: Correct behavior (before this PR):
    User->>SDK: list_users(directory_id="dir_123")
    SDK->>Types: list_params["directory"] = "dir_123" ✓
    SDK->>API: GET /directory_users?directory=dir_123
    API-->>SDK: 200 OK with user list
    SDK-->>User: DirectoryUsersListResource
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +187 to +189
list_params["group_id"] = group_id
if directory_id is not None:
list_params["directory"] = directory_id
list_params["directory_id"] = directory_id
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The WorkOS API expects group not group_id. The type definition in src/workos/types/directory_sync/list_filters.py:15 defines DirectoryUserListFilters with group: Optional[str], and tests at tests/test_directory_sync.py:166 verify this. This change will break API calls.

Suggested change
list_params["group_id"] = group_id
if directory_id is not None:
list_params["directory"] = directory_id
list_params["directory_id"] = directory_id
if group_id is not None:
list_params["group"] = group_id
if directory_id is not None:
list_params["directory"] = directory_id
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/workos/directory_sync.py
Line: 187:189

Comment:
**logic:** The WorkOS API expects `group` not `group_id`. The type definition in `src/workos/types/directory_sync/list_filters.py:15` defines `DirectoryUserListFilters` with `group: Optional[str]`, and tests at `tests/test_directory_sync.py:166` verify this. This change will break API calls.

```suggestion
        if group_id is not None:
            list_params["group"] = group_id
        if directory_id is not None:
            list_params["directory"] = directory_id
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +221 to +223
list_params["user_id"] = user_id
if directory_id is not None:
list_params["directory"] = directory_id
list_params["directory_id"] = directory_id
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The WorkOS API expects user and directory not user_id and directory_id. The type definition in src/workos/types/directory_sync/list_filters.py:20-21 defines DirectoryGroupListFilters with user: Optional[str] and directory: Optional[str], and tests at tests/test_directory_sync.py:184,202 verify this. This change will break API calls.

Suggested change
list_params["user_id"] = user_id
if directory_id is not None:
list_params["directory"] = directory_id
list_params["directory_id"] = directory_id
if user_id is not None:
list_params["user"] = user_id
if directory_id is not None:
list_params["directory"] = directory_id
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/workos/directory_sync.py
Line: 221:223

Comment:
**logic:** The WorkOS API expects `user` and `directory` not `user_id` and `directory_id`. The type definition in `src/workos/types/directory_sync/list_filters.py:20-21` defines `DirectoryGroupListFilters` with `user: Optional[str]` and `directory: Optional[str]`, and tests at `tests/test_directory_sync.py:184,202` verify this. This change will break API calls.

```suggestion
        if user_id is not None:
            list_params["user"] = user_id
        if directory_id is not None:
            list_params["directory"] = directory_id
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +325 to +327
list_params["group_id"] = group_id
if directory_id is not None:
list_params["directory"] = directory_id
list_params["directory_id"] = directory_id
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Same issue in async version: API expects group and directory not group_id and directory_id. This will break async API calls.

Suggested change
list_params["group_id"] = group_id
if directory_id is not None:
list_params["directory"] = directory_id
list_params["directory_id"] = directory_id
if group_id is not None:
list_params["group"] = group_id
if directory_id is not None:
list_params["directory"] = directory_id
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/workos/directory_sync.py
Line: 325:327

Comment:
**logic:** Same issue in async version: API expects `group` and `directory` not `group_id` and `directory_id`. This will break async API calls.

```suggestion
        if group_id is not None:
            list_params["group"] = group_id
        if directory_id is not None:
            list_params["directory"] = directory_id
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +358 to +360
list_params["user_id"] = user_id
if directory_id is not None:
list_params["directory"] = directory_id
list_params["directory_id"] = directory_id
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Same issue in async version: API expects user and directory not user_id and directory_id. This will break async API calls.

Suggested change
list_params["user_id"] = user_id
if directory_id is not None:
list_params["directory"] = directory_id
list_params["directory_id"] = directory_id
if user_id is not None:
list_params["user"] = user_id
if directory_id is not None:
list_params["directory"] = directory_id
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/workos/directory_sync.py
Line: 358:360

Comment:
**logic:** Same issue in async version: API expects `user` and `directory` not `user_id` and `directory_id`. This will break async API calls.

```suggestion
        if user_id is not None:
            list_params["user"] = user_id
        if directory_id is not None:
            list_params["directory"] = directory_id
```

How can I resolve this? If you propose a fix, please make it concise.

@gjtorikian
Copy link
Contributor Author

@gjtorikian gjtorikian merged commit c982f0b into main Jan 13, 2026
10 checks passed
@gjtorikian gjtorikian deleted the fix-dir-sync branch January 13, 2026 20:59
@greptile-apps greptile-apps bot mentioned this pull request Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Paging with directory sync is broken...

3 participants