feat: Support clearing nullable fields via explicit nil - #521
feat: Support clearing nullable fields via explicit nil#521devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Nullable optional body params now default to a generated WorkOS::OMIT sentinel. Omitting an argument leaves the field unchanged; passing an explicit nil sends JSON null to clear it (e.g. Organization/User external_id). base_client no longer .compact-s the request body so intentional nils survive serialization.
Original prompt from heather
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThis PR introduces a
Confidence Score: 4/5Safe to merge with one outstanding concern in user_management.rb worth resolving before a public release. The sentinel design is sound and the base_client change is well-scoped. The main open question is in create_user: every optional field (first_name, last_name, name, email_verified, ip_address, user_agent) was switched to WorkOS::OMIT, meaning an explicit nil now sends JSON null to the API for each of those fields. update_user keeps those same fields nil-defaulted inside .compact, so the wire behaviour diverges between create and update for identical caller code. If the create-user endpoint does not accept null for those fields, callers who currently pass them as nil expecting a silent omit will start seeing API errors after upgrading. lib/workos/user_management.rb — verify that first_name, last_name, name, email_verified, ip_address, and user_agent are genuinely nullable in the create-user OpenAPI spec before shipping. Important Files Changed
Reviews (2): Last reviewed commit: "test: Assert WorkOS::OMIT sentinel never..." | Re-trigger Greptile |
|
Re: the
So the create endpoint genuinely accepts |
Description
Lets callers clear a nullable API field (e.g. an Organization/User
external_id) through the normal SDK methods, instead of hand-building a rawNet::HTTPrequest with JSONnull.Previously every optional body param defaulted to
nil, and both the generated method andbase_client.compact-ed the body — so an explicitexternal_id: nilwas indistinguishable from an omitted argument and got stripped. There was no way to send JSONnull.Now, nullable optional params default to a generated
WorkOS::OMITsentinel:nil→ field is sent as JSONnull(clears it)Non-nullable optional params keep their exact current behavior (
nilstill means "omit").What changed
WorkOS::OMIT; the generated method compacts only the non-nullable literal and conditionally assigns nullable fields so an explicitnilsurvives.lib/workos.rb: defines theWorkOS::OMITsentinel.lib/workos/base_client.rb(hand-maintained): request bodies are no longer.compact-ed, so the intentionalnilplaced by generated methods serializes to JSONnull. Verified safe — all body-building callers (generated + hand-maintained likepasswordless/session) already drop unset optionals before the body reachesbase_client.This scope is limited to fields marked nullable in the OpenAPI spec (
type: [string, 'null']), matching what the API actually allows to be cleared.Supersedes the earlier hand-written
WorkOS::Nullstopgap (#519), which introduced a caller-facing sentinel; this uses the codegen approach agreed on so Ruby/Python/Go stay consistent.Testing
test/workos/test_nullable_clearing.rbasserts omitted → absent, explicitnil→ JSONnull, and value → value, for Organization and Userexternal_id.Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
Link to Devin session: https://app.devin.ai/sessions/127c630f46c54bc0be571814c75047e8