fix(flags): relax StatsigEventSerializer to accept nested user fields and blank values#119478
Draft
billyvg wants to merge 1 commit into
Draft
fix(flags): relax StatsigEventSerializer to accept nested user fields and blank values#119478billyvg wants to merge 1 commit into
billyvg wants to merge 1 commit into
Conversation
Statsig sends nested objects (customIDs, custom, statsigEnvironment) as values within the `user` field, empty strings for `value`, and non-UUID strings for `timeUUID`. The overly-strict serializer was raising DeserializationError for all of these, even though none of these fields are used in the audit log logic. Fixes: - Remove child=serializers.CharField() from user DictField so nested objects/lists are accepted - Add allow_blank=True to value CharField - Change timeUUID from UUIDField to CharField since it's not validated and callers send arbitrary strings Fixes SENTRY-5J6Z Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0184E4PYCz4ekKHjv3cZkUJT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a production
DeserializationErrorin the Statsig webhook handler (SENTRY-5J6Z) that has been generating ~2.75M errors affecting 4,825 users since 2026-02-07.Root Cause
StatsigEventSerializerwas too strict about the shape of optional fields that are never actually used in the audit log business logic:userDictField withchild=serializers.CharField(): Statsig sends nested objects (e.g.customIDs: {"companyID": "acme"},custom: {"role": "admin"},statsigEnvironment: {"tier": "production"}) as values within theuserdict. Thechild=serializers.CharField()constraint rejects any value that isn't a plain string.value = serializers.CharField(required=False): Statsig sendsvalue=""(empty string) which fails the defaultallow_blank=Falseon CharField.timeUUID = serializers.UUIDField(required=False): Statsig sends arbitrary string values that aren't valid UUIDs.Fix
child=serializers.CharField()fromuserDictField — the field accepts any dict structure nowallow_blank=TruetovalueCharFieldtimeUUIDfromUUIDFieldtoCharField(allow_blank=True)— we never validate or use this fieldNone of these fields are used in the audit log rows produced by
StatsigProvider.handle(). The business logic only readsuser.email,user.userID,user.name,userID,eventName,timestamp, andmetadatafrom each event.Evidence
Sentry issue: https://sentry.sentry.io/issues/SENTRY-5J6Z
StatsigEventSerializerfor unused fields causesDeserializationErrorwhen processing Statsig webhooks containing unexpected formats like nested objects or empty strings."Example failing payload fragment:
{ "user": { "userID": "...", "customIDs": {"companyID": "acme"}, "custom": {"role": "admin"}, "statsigEnvironment": {"tier": "production"} }, "value": "", "timeUUID": "not-a-uuid" }Test Plan
Added
test_handle_nested_user_fieldswhich covers the exact pattern from the failing production events (nested user dict values, blankvalue, non-UUIDtimeUUID).Session: https://claude.ai/code/session_0184E4PYCz4ekKHjv3cZkUJT
Generated by Claude Code