fix(analytics): SelectedVariant#to_h recurses into FallbackReason (SDK-125)#165
Merged
Merged
Conversation
The parent to_h was returning @fallback_reason as the raw
FallbackReason object rather than the {kind:, message:} hash the
FallbackReason class itself defines. Downstream serializers
(to_json, structured logging, cross-process passing) received the
object's inspect representation instead of the intended hash.
Fix: `@fallback_reason&.to_h` — the nil-safe form covers matched
variants where fallback_reason is nil.
Added spec/mixpanel-ruby/flags/types_spec.rb covering the direct
hash form, the JSON round-trip, and the nil-fallback compaction
path. All three of the new cases fail on master; all pass now.
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| lib/mixpanel-ruby/flags/types.rb | Serializes the optional fallback reason through its existing to_h method. |
| spec/mixpanel-ruby/flags/types_spec.rb | Covers matched variants, nested fallback hashes, JSON output, and absent fallback reasons. |
Reviews (2): Last reviewed commit: "Merge branch 'master' into fix/sdk-125-t..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #165 +/- ##
=========================================
Coverage ? 97.25%
=========================================
Files ? 15
Lines ? 764
Branches ? 0
=========================================
Hits ? 743
Misses ? 21
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ketanmixpanel
approved these changes
Jul 21, 2026
tylerjroach
enabled auto-merge (squash)
July 21, 2026 14:19
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
SelectedVariant#to_hwas returning@fallback_reasonas the rawFallbackReasonobject instead of the{kind:, message:}hash the class itself defines. Downstream serializers (.to_json, structured logging) got the object'sinspectrepresentation.@fallback_reason&.to_h(nil-safe covers matched variants where the field is nil).spec/mixpanel-ruby/flags/types_spec.rbcovering direct hash form, JSON round-trip, and nil-fallback compaction.Follow-up to SDK-79 caught by Greptile immediately after PR #153 merged.
Test plan
bundle exec rspec spec/mixpanel-ruby/flags/types_spec.rb— 4 pass on this branch, 2 fail on master (round-trip + nested-hash assertions)bundle exec rspec spec/mixpanel-ruby/flags/— full 99-test flag suite greenLinear: SDK-125