Skip to content

list_* functions pass the collection type to Page.from_map, so every item parses to an empty wrapper (3.0.0) #112

Description

@georgeguimaraes

in workos 3.0.0, every list endpoint that has a dedicated *List wrapper type parses each item with the wrong from_map, so items come back empty and all their real fields are gone.

WorkOS.Page.from_map(body, data_key, cast_item, fetch_next) maps cast_item over each element of body[data_key], so cast_item has to be the element caster. A bunch of the generated list_* functions pass the collection caster instead.

WorkOS.OrganizationMembershipService.list_organization_memberships:

WorkOS.Page.from_map(body, "data", &WorkOS.UserOrganizationMembershipList.from_map/1, fetch_next)

That &UserOrganizationMembershipList.from_map/1 runs against each individual membership map. A single membership has no data/list_metadata keys, so every element comes out as:

%WorkOS.UserOrganizationMembershipList{object: "organization_membership", data: nil, list_metadata: nil}

and id / user_id / organization_id are dropped. Reading membership.organization_id then raises KeyError.

Same in WorkOS.UserManagement.list_users:

WorkOS.Page.from_map(body, "data", &WorkOS.UserList.from_map/1, fetch_next)  # should be &WorkOS.User.from_map/1

Grepping the generated code, the callers passing a *List type are all wrong:

  • list_organization_memberships -> UserOrganizationMembershipList (should be UserOrganizationMembership)
  • list_users -> UserList (should be User)
  • list_invitations -> UserInviteList
  • list_user_api_keys -> UserApiKeyList
  • group memberships -> GroupList

The ones passing an element type (CORSOriginResponse, UserSessionsListItem, RedirectUri) parse fine, so this looks like a codegen bug: wherever a *List wrapper type exists, the generator wired the wrapper in place of the element type.

Repro: call any of the above with at least one result. Confirmed on 3.0.0 against a stubbed response.

Fix is per function, swap the collection caster for the element one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions