feat: Support clearing nullable fields via explicit None - #693
feat: Support clearing nullable fields via explicit None#693devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Nullable optional body params now default to a NOT_GIVEN sentinel. Omitting an argument leaves the field unchanged; passing an explicit None sends JSON null to clear it (e.g. Organization/User external_id). Adds NotGiven/NOT_GIVEN to _types.py.
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: 5/5Safe to merge — the sentinel is only applied to fields the OpenAPI spec marks nullable, the identity-check guards are consistent across all resources, and existing callers who omit these params see no behavior change. Every changed field has an No files require special attention. Important Files Changed
|
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 raw request with JSONnull.Previously every optional body param defaulted to
None, and the generated method built the body with{k: v ... if v is not None}— so an explicitexternal_id=Nonewas indistinguishable from an omitted argument and got stripped. There was no way to send JSONnull.Now, nullable optional params default to a
NOT_GIVENsentinel:None→ field is sent as JSONnull(clears it)Non-nullable optional params keep their exact current behavior (
Optional[T] = None,None= omit).What changed
Union[T, None, NotGiven] = NOT_GIVEN; the generated method builds the non-nullable literal with the existingif v is not Nonefilter and conditionally assigns nullable fields withif x is not NOT_GIVEN, so an explicitNonesurvives.src/workos/_types.py(hand-maintained,@oagen-ignore-file): adds theNotGivensentinel type andNOT_GIVENinstance imported by generated modules._base_client.requestpassesjson=bodystraight to httpx, so an explicitNonein the body serializes to JSONnull.Scope is limited to fields marked nullable in the OpenAPI spec (
type: [string, 'null']), matching what the API allows to be cleared. Applies to both sync and async clients.Part of the cross-SDK effort (Ruby workos/workos-ruby#521, Go to follow) to make nullable clearing consistent.
Testing
tests/test_nullable_clearing.pyasserts omitted → absent, explicitNone→ JSONnull, and value → value, for Organization and Userexternal_id(sync + async).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