Skip to content

Conversation

@diederich
Copy link

When setting the user via identify, any observers were not notified about flag changes, although the underlying store changed.

This PR fixes that by calling into the "notify machinery" when swapping out the underlying data.

Requirements

  • [-] I have added test coverage for new or changed functionality
  • [-] I have followed the repository's pull request submission guidelines
  • [-] I have validated my changes against all supported platform versions

when setting the user via `identify`, any observers were not notified about flag changes,
although the underlying store changed.

Fix that by calling into the notify machinery when swapping out the underlying data.
@diederich
Copy link
Author

👋 Hey there - we just realised that calling identify did not call the feature-flag changed observers. I'm not sure this is by design or was an oversight. If this is by design - is there any other way to be notified of changes?

@lukeredpath
Copy link

I’ve just run into this problem - we have an observer that runs for the duration of an app session and an account switch feature that triggers a call to identify - the observer does not detect changes when calling identify. The observer is still working though and will pick up a change if I toggle a flag on and off.

We are using streaming mode - I wonder if this problem also affects polling mode.

@lukeredpath
Copy link

For anyone interested in a workaround while this PR is open, I have taken advantage of the fact that the client is taken offline temporarily whenever you call .identify - this means you can create a connection state observer and whenever the state changes to polling or streaming to indicate it is back online again, you can notify your observers of the current flag value.

@jasdev
Copy link

jasdev commented Oct 25, 2021

@gwhelanLD, @louis-launchdarkly — sorry for the @, but any chance we could get some eyes on this when y’all get a moment? 🙏🏽

@louis-launchdarkly
Copy link
Contributor

louis-launchdarkly commented Oct 26, 2021

Hello @diederich, @lukeredpath, @jasdev Apologize and thank you for reaching out, for looking at this, and for waiting. @gwhelanLD and I had discussed this, and here are a few thoughts:

  1. The flagChangeNotifier.notifyObservers() method is currently used when the flag is changed from a Sync (i.e. someone modified the flag in LaunchDarkly, and the SDK received the change, which is different from this proposal, when the flag values are different, due to change in User context. So just calling notifyObservers may create confusion here.

  2. However, it is reasonable to want to know "Did identify change the current flag values in the SDK?". Similarly, some users may not want to know as there is an identify event already to note that flag context is being replaced by identify.

  3. To serve the diverging needs, it seems that it is helpful to have means to control this behavior. We will need to evaluate more before we can propose a solution, but we are looking into it.

Filed internally as 128729

fischman-bcny and others added 2 commits March 28, 2022 13:47
Recipe:

Sync'd the repo:
![SCR-20220328-j1s](https://user-images.githubusercontent.com/94327711/160486865-207d0e55-a7b6-445d-9701-981b73ce942a.png)
![SCR-20220328-j30](https://user-images.githubusercontent.com/94327711/160486844-7284c193-5b91-4e17-a91f-622da3dd23b5.png)

Then merge into our feature branch with:
```
git clone git@github.com:thebrowsercompany/ios-client-sdk.git
cd ios-client-sdk
git checkout -b feature/notify-observers-on-identifyUser-flag-changes origin/feature/notify-observers-on-identifyUser-flag-changes
git merge v5
git push -n origin HEAD:ami/notify-observers-on-identifyUser-flag-change
git push origin HEAD:ami/notify-observers-on-identifyUser-flag-change
```

Then manually updated the destination repo & branch in GitHub's "Open a pull request" page.

Note for future travelers: an alternative to syncing the entire repo from upstream using the webapp above is to:
```
git add remote upstream git@github.com:launchdarkly/ios-client-sdk.git
git fetch --all
git checkout -b feature/notify-observers-on-identifyUser-flag-changes origin/feature/notify-observers-on-identifyUser-flag-changes
git merge upstream/v5
```
@fischman-bcny
Copy link

@louis-launchdarkly any update on this / internal 128729 ?

tanderson-ld pushed a commit that referenced this pull request Sep 19, 2023
We have discussed and agreed to modify the logic to not include the
version as the context key generation. We will release this as a bug fix
to make sure customers don't stuck on a version with old logic
available.
@brianmichel
Copy link

Hey @louis-launchdarkly any chance we can get this merged? We'd love to delete our internal fork and use the main LD library, happy to help out here in any way, just let me know :D

@louis-launchdarkly
Copy link
Contributor

Hello @brianmichel, I am really sorry for the late reply. We are currently doing an audit of all the Client-side SDKs from LaunchDarkly, and are trying to line up the behavior of each SDK with this request in mind. That will inform can we merge this or adopt the change in the new callback design.

@patriknyblad
Copy link

Just wanted to chime in here and say that we also have issues with this and have been debugging what is going on this week. In the end we implemented a patch in our middle layer code that triggers all observers when we update the context.

If the LDClient got all the updated flags internally when changing context... shouldn't the observers also be notified?
Surely this must be an important bug to fix asap?

@brianmichel
Copy link

@louis-launchdarkly @gwhelanLD any updates here?

@brianmichel
Copy link

Actually, it looks like this is resolved in the latest v9 commits?

let cachedContextFlags = self.flagCache.retrieveFeatureFlags(contextKey: self.context.fullyQualifiedHashedKey()) ?? [:]
let oldItems = flagStore.storedItems.featureFlags
flagStore.replaceStore(newStoredItems: cachedContextFlags)
flagChangeNotifier.notifyObservers(oldFlags: oldItems, newFlags: flagStore.storedItems.featureFlags)
self.service.context = self.context
self.service.clearFlagResponseCache()

@louis-launchdarkly
Copy link
Contributor

Hello @patriknyblad and @brianmichel, sorry for the late reply to this issue. From the investigation, this is missed from the iOS and not some intentional behavior, and this was fixed in both https://github.com/launchdarkly/ios-client-sdk/releases/tag/8.3.1 and https://github.com/launchdarkly/ios-client-sdk/releases/tag/9.2.1

Can you please verify that this fixed your issue?

@brianmichel
Copy link

Hello @patriknyblad and @brianmichel, sorry for the late reply to this issue. From the investigation, this is missed from the iOS and not some intentional behavior, and this was fixed in both https://github.com/launchdarkly/ios-client-sdk/releases/tag/8.3.1 and https://github.com/launchdarkly/ios-client-sdk/releases/tag/9.2.1

Can you please verify that this fixed your issue?

@louis-launchdarkly I don't think this is fixed exactly, see #331 that I just filed

@patriknyblad
Copy link

@louis-launchdarkly We have been able to remove our local fix after updating the SDK. We were in contact with LD support directly and the issue is fixed for us 🙏

@keelerm84
Copy link
Member

Closing this PR as the fix from a previous commit seems to have done the trick for everyone.

@keelerm84 keelerm84 closed this Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants