Skip to content

Exclude transient query parameter from identities request when false#64

Merged
rolodato merged 3 commits intoFlagsmith:fix/exclude-transient-falsefrom
caselett:fix/exclude-transient-query-false
Jun 24, 2025
Merged

Exclude transient query parameter from identities request when false#64
rolodato merged 3 commits intoFlagsmith:fix/exclude-transient-falsefrom
caselett:fix/exclude-transient-query-false

Conversation

@caselett
Copy link
Copy Markdown
Contributor

Currently, get identities request contains transient query parameter only when set to true.

Previously, this bug would result in an unexpected flag state for the user identity.

@matthewelwell
Copy link
Copy Markdown
Contributor

Hi @SergeiRR , thanks for the contribution. I have a feeling, however, that this is a duplicate of a PR that was merged earlier this week here?

@caselett
Copy link
Copy Markdown
Contributor Author

Hi @matthewelwell, actually, this is another side of the issue.
PR you mentioned covered responce part, but my PR covers request part.

@matthewelwell
Copy link
Copy Markdown
Contributor

Hi @matthewelwell, actually, this is another side of the issue. PR you mentioned covered responce part, but my PR covers request part.

I'm not sure I understand what you mean by 'response' part, but on inspection, I think that the PR I shared only covers the POST by modifying the request / json body, not the GET request.

@rolodato are you able to contribute to the conversation here?

@caselett
Copy link
Copy Markdown
Contributor Author

caselett commented May 30, 2025

@matthewelwell Anyway, we found this issue using 1.7.3 (the latest) version.
When transient exists (even it false) as query parameter server responds with default value.
This PR fixes the issue.

@matthewelwell
Copy link
Copy Markdown
Contributor

Ok, thanks @SergeiRR - is there a way to catch this further upstream though? It seems like the queryInterceptor is having to correct something that's happened earlier in the URL building - couldn't we just prevent the query parameter being added earlier in the codepath?

@caselett
Copy link
Copy Markdown
Contributor Author

@matthewelwell yes, we can use null value for transient query parameter, but we will face necessity to add check like:

if (transient) transient else null

to every function call (currently there are 2 calls that use transient parameter).

But this may cause misunderstandings in the future.

@caselett
Copy link
Copy Markdown
Contributor Author

@matthewelwell Hi, any activity on this? This issue still affects us.

@rolodato
Copy link
Copy Markdown
Contributor

rolodato commented Jun 23, 2025

I understand the correct fix would be to remove the call to GET /identities altogether, which does not have this problem, based on @matthewelwell's comment here: Flagsmith/flagsmith#5260 (comment).

However, we can't simply switch from GET to POST calls because of how the client implements caching. We cache API responses by adding a Cache-Control headers to responses, and letting OkHttp handle the caching:

.let { if (cacheConfig.enableCache) it.addNetworkInterceptor(cacheControlInterceptor()) else it }

The problem is that OkHttp will not cache POST responses: https://github.com/square/okhttp/blob/2f78681a1f5ef5d9cc4f7bce48b9975f79c06978/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Cache.kt#L231-L235

This means that we would need to implement our own caching separate from OkHttp.

As an interim solution, I changed this PR's approach to:

  • Not include the transient parameter in requests by changing the signature of getIdentityFlagsAndTraits to accept an optional Boolean that defaults to null, which should be backwards compatible. This works because a null query string parameter is not serialised, whereas a false value gets serialised as transient=false
  • Explicitly check that the parameter is missing, instead of expecting a generic AssertionError

@rolodato rolodato requested a review from matthewelwell June 23, 2025 22:03
Copy link
Copy Markdown
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rolodato I'm not sure that this is actually any improvement on @SergeiRR 's implementation since we still have the interceptor logic included which was what I was hoping that we could remove.

I do see, however, that we should include it, even with your change, in case any user explicitly sets transient: false.

I'm unsure then what benefit we get from including your change?

@rolodato
Copy link
Copy Markdown
Contributor

It would have been an improvement, if I had remembered to actually remove the interceptor :) It's fixed now.

@rolodato rolodato requested a review from matthewelwell June 24, 2025 12:22
@matthewelwell
Copy link
Copy Markdown
Contributor

matthewelwell commented Jun 24, 2025

@rolodato can you merge this into a native branch, other than main, so we can verify the test / build process and then let's get it merged and released.

@rolodato rolodato changed the base branch from main to fix/exclude-transient-false June 24, 2025 12:46
@rolodato rolodato merged commit 1a35341 into Flagsmith:fix/exclude-transient-false Jun 24, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants