mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
* Fix HTTP request deduplication bug caused by non-deterministic dictionary ordering ## Problem HTTP requests were not being properly deduplicated when they should have been. In production, we observed two POST receipt requests with identical content except for the $attConsentStatus timestamp (88ms apart), which should have been deduplicated but weren't. The root cause was that `individualizedCacheKeyPart` used `debugDescription` on the dictionary, which doesn't guarantee consistent ordering. This caused identical requests to generate different cache keys, preventing deduplication. ## Solution Changed the cache key computation to sort dictionary keys alphabetically before building the cache key string. This ensures deterministic ordering regardless of dictionary insertion order. ## Tests Added 1. Unit test: `testDictionaryIndividualizedCacheKeyPartIsDeterministicRegardlessOfInsertionOrder` - Verifies cache keys are identical despite different insertion orders - Verifies alphabetical sorting of keys in the output - FAILS without the fix, PASSES with it 2. Integration test: `testPostReceiptCachesRequestsWithMultipleAttributesAndDifferentConsentStatusTimestamps` - Tests full POST receipt flow with multiple attributes - Uses different dictionary insertion orders (AMZ vs ZMA) - Verifies only one HTTP request is made (deduplication works) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Remove force unwrap --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: Rick van der Linden <rick.vanderlinden@revenuecat.com>