Skip to content

Commit c6ae0e0

Browse files
Fix InternalStore.removeOverride to call saveOverrides for state persistence (#412)
# Fix InternalStore.removeOverride to call saveOverrides for state persistence ## Summary Fixes bug where `InternalStore.removeOverride()` doesn't call `saveOverrides()` and thus prevents state from being persisted. The method was removing override values from the in-memory `localOverrides` dictionary but not saving the changes to `StatsigUserDefaults`, causing removed overrides to reappear after app restart. **Root cause:** All other override methods (`overrideGate`, `overrideConfig`, `overrideLayer`, `overrideParamStore`) follow the pattern of calling `saveOverrides()` after modifying the `localOverrides` dictionary, but `removeOverride` was missing this call. **Fix:** Added `self?.saveOverrides()` call inside the async barrier block in `removeOverride()` to match the existing pattern. ## Review & Testing Checklist for Human - [ ] **Test override persistence across app restarts** - Verify that when you remove an override, it stays removed after killing and restarting the app (this was the core bug) - [ ] **Run existing LocalOverridesSpec tests** - Ensure all override removal tests in `Tests/StatsigTests/LocalOverridesSpec.swift` still pass - [ ] **Verify threading safety** - Confirm the `saveOverrides()` call is correctly placed inside the `storeQueue.async(flags: .barrier)` block --- ### Diagram ```mermaid %%{ init : { "theme" : "default" }}%% graph TB API["Statsig.removeOverride()"]:::context Client["StatsigClient.removeOverride()"]:::context Store["InternalStore.removeOverride()"]:::major-edit SaveMethod["InternalStore.saveOverrides()"]:::context UserDefaults["StatsigUserDefaults"]:::context API --> Client Client --> Store Store --> SaveMethod SaveMethod --> UserDefaults Store -.-> |"NEW: Added missing call"| SaveMethod subgraph Legend L1["Major Edit"]:::major-edit L2["Minor Edit"]:::minor-edit L3["Context/No Edit"]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFF ``` ### Notes - **Risk level: Low** - Single line addition following established pattern - **Testing limitation:** Unable to run Swift tests locally due to missing build tools, relying on CI - **Pattern consistency:** Change makes `removeOverride` consistent with all other override methods - **Thread safety:** Change maintains existing threading model using barrier queue **Link to Devin run:** https://app.devin.ai/sessions/571fff3bed7b4370956aa20c546971f1 **Requested by:** Andre Terron (@andre-statsig) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 2c254a2 commit c6ae0e0

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

Sources/Statsig/InternalStore.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ class InternalStore {
786786
self?.localOverrides[jsonDict: InternalStore.configsKey]?.removeValue(forKey: name)
787787
self?.localOverrides[jsonDict: InternalStore.layerConfigsKey]?.removeValue(forKey: name)
788788
self?.localOverrides[jsonDict: InternalStore.paramStoresKey]?.removeValue(forKey: name)
789+
self?.saveOverrides()
789790
}
790791
}
791792

0 commit comments

Comments
 (0)