Skip to content

Accept an omitted value as null on PUT /v1/members/{id}/fields - #274

Open
SiteRelEnby wants to merge 1 commit into
mainfrom
fix/custom-field-clear-omitted-value
Open

Accept an omitted value as null on PUT /v1/members/{id}/fields#274
SiteRelEnby wants to merge 1 commit into
mainfrom
fix/custom-field-clear-omitted-value

Conversation

@SiteRelEnby

Copy link
Copy Markdown
Contributor

Fixes clearing a member custom field from clients whose JSON serialiser omits null object fields (Moshi on Android is how this surfaced: emptying a field serialised to [{"field_id": ...}] and the whole request 422'd - see sheaf-project/android#68 for the client-side half).

value: Any with no default is a required field in Pydantic v2, so an entry that omitted value was rejected outright. It now defaults to None, making an omitted value clear the field exactly like an explicit null. This is safe because absence has no other meaning on this endpoint: the handler upserts every entry it is given, there is no omit-to-leave-alone mode, and None already flows correctly through type validation, the text cap, and encrypted storage. Clients that send the explicit null are unchanged.

Checked for siblings: the only other no-default Any in the schemas is a response model, and the PATCH endpoints that do distinguish omitted from null (fields_set semantics) are deliberate and untouched.

Regression test pins both clearing spellings as equivalent. Full behavioural config green. The Android explicit-null fix remains necessary independently - self-hosted servers upgrade on their own schedule, so this is defence in depth for other clients, not a replacement.

Clearing a custom field is expressed as value: null, but value: Any with
no default is a required field in Pydantic v2, so an entry that omits
value entirely was rejected and the whole request 422'd. Several client
serialisers drop null object fields by default - Moshi on Android is how
this surfaced: emptying a field serialised to [{"field_id": ...}] and
clearing silently failed.

Absence has no other meaning on this endpoint: the handler upserts every
entry it is given and there is no omit-to-leave-alone mode, so omitted
can only sensibly mean the same as an explicit null. Defaulting the
field accepts it as exactly that. Clients already sending the null are
unchanged. Regression test pins both clearing spellings as equivalent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant