Repository navigation
fix(sdk): the Flutter SDK sends the user's attributes when it evaluates a flag - #2062
Open
amarkanday wants to merge 4 commits into
Open
amarkanday wants to merge 4 commits into
amarkanday wants to merge 4 commits into
Conversation
…es a flag
evaluateFlag took an attributes argument and ignored it: the request was
GET /api/v1/feature-flags/evaluate/{key}?user_id=... with nothing else, so a
flag rule on an attribute never matched from a Flutter app, while the same
attributes went out as the context of an experiment assignment.
evaluateFlag now sends them as `context`, after `user_id`, through the
encoder `user_id` already uses (Uri.encodeQueryComponent), and isEnabled gains
the same named argument. With no attributes, or an empty map, the request is
the one sent before, byte for byte.
- The cache keeps one entry per user + flag together with the context it was
answered for; a call with other attributes asks the server again and
replaces it. The keys of every object are sorted, so the same attributes in
another order are one cache slot. The in-flight key carries the context.
- The offline store key is unchanged: the last answer for any attributes,
read only when the server cannot answer, removed by a 404.
- Attributes that cannot be written as JSON give the disabled answer before
the cache, the dedupe and the offline store; nothing is sent.
- A network error's message is fixed text: the transport error's own text
names the request URI, query included, so none of it is kept.
This completes #438 for the native SDKs, so the shared sentences, the
Limitations row and their claims units go, with the native-SDK source test
and NATIVE_SDKS, and video 4's description no longer names a native limit.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011kqtSDC7sd5ue3m6LuwdXV
Signed-off-by: amarkanday <a.markanday@gmail.com>
…here When the attributes cannot be written as JSON, evaluateFlag returns the disabled answer and sends nothing; the SDK also logs nothing, so the disabled answer is the only sign. The page and the README now say so, and the sentence pin carries the same text. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kqtSDC7sd5ue3m6LuwdXV Signed-off-by: amarkanday <a.markanday@gmail.com>
Main took the Ruby, PHP, Edge and Elixir SDK changes since this branch was cut. They change the same two test files as this change, so the merge conflicts in exactly those two, and the resolution keeps both sides' entries (MERGE-RULES-A1 "Server family" union and the Flutter section's union sentences; merge, no rebase, no force push). iOS and Android have not merged, so they stay where main has them. - backend/tests/unit/api/test_documented_limits.py: SENDS is the union of main's ruby, php, edge and elixir entries and Flutter's; DOES_NOT_SEND loses flutter and keeps ios and android. - backend/tests/unit/docs/test_deferred_sdk_pages.py: SENDS_NO_CONTEXT loses flutter and keeps android and ios; Flutter's section 9 and its claim-pattern test are kept beside the Ruby, PHP, Edge and Elixir sections and tests. The file is main's, with exactly this change's three insertions applied. No other file conflicted, so the Flutter section's nine take-whole files and the showcase test did not come into play: nothing outside the two files' shared lines changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kqtSDC7sd5ue3m6LuwdXV Signed-off-by: amarkanday <a.markanday@gmail.com>
Brings the Flutter branch up to main 9448fb3, which holds the iOS (#2045), #1747 (#2046) and Android (#2074) changes. Twelve files conflicted. Main also changed some of them for unrelated reasons (the AWS CDK two-step sign-in row and its tests, the front matter of the Limitations page), so each is resolved from main's version with this branch's own change applied on top, not by taking this branch's whole file. Main's version plus this branch's change (ten files; where the iOS or Android edit and this branch's edit touched the same sentence, this branch's wording wins, because it deletes the sentence): - demo/DEMO_GUIDE.md - demo/streampulse/README.md - docs/guides/guided-examples.md - docs/getting-started/limitations.md - docs/_claims/demo/DEMO_GUIDE.md.toml - docs/_claims/demo/streampulse/README.md.toml - docs/_claims/docs/getting-started/limitations.md.toml - docs/_claims/docs/guides/guided-examples.md.toml - frontend/src/content/videos.json - backend/tests/unit/showcase/test_site_walkthroughs.py The union of both sides: - backend/tests/unit/api/test_documented_limits.py: SENDS holds the iOS, Android and Flutter entries beside the server SDKs already on main. The native-SDK block, its helpers and its test stay deleted. Every SDK now sends the context, so DOES_NOT_SEND is empty and is deleted with the code that only read it; the classification test keeps checking SENDS. - backend/tests/unit/docs/test_deferred_sdk_pages.py: SENDS_NO_CONTEXT is empty and is deleted with the two tests that only read it and the assertions that an SDK is not in it; the check that every deferred SDK sends the context stays, and fails naming the SDK that stops. Every SDK's own section and page tests are kept, and this branch's section is numbered 10, so that it no longer shares a number with the Android section. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NpxPyav9uBxNuiXsDvD8qn Signed-off-by: amarkanday <a.markanday@gmail.com>
This branch has not been deployed
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.
Resolves #438
Related: #2017 (SDK contract tests: a targeted flag for the iOS, Android and Flutter SDKs, from #438), the issue that holds the contract-test sentence of #438.
What changed
The Flutter SDK now sends the user's attributes when it evaluates a flag:
GET /api/v1/feature-flags/evaluate/{key}?user_id=...&context=<percent-encoded compact JSON>,contextafteruser_id. Before, the attributes were accepted and dropped, so a targeting rule on a user attribute never matched. A call with no attributes (none or{}) sends the same bytes as before.isEnabledgains{attributes}.This is the last SDK of the mobile family, so it also finishes the shared-page sweep: with iOS and Android sending attributes, no native SDK is left that sends only the user id, so the limitations row, the guided-examples and demo sentences, and the four claims units that covered them are deleted whole, and video 4's description ends
The demo uses the web SDK.Branch
a1-flutter, headd15bac5a, two commits on main: the change (e839f0e9) andd15bac5a(the page says unsendable attributes are logged nowhere).git diff --stat origin/main...HEAD: 18 files, +769/-177.sdk/flutter/lib/src/client.dart,http_client.dart,cache.dart,sdk/flutter/test/client_test.dartdocs/sdk/flutter.md,sdk/flutter/README.mddocs/getting-started/limitations.md(row removed),docs/guides/guided-examples.md,demo/DEMO_GUIDE.md,demo/streampulse/README.md, and the fourdocs/_claims/**.tomlunits (deleted whole)backend/tests/unit/api/test_documented_limits.py(NATIVE_SDKS, its test,_native_codeand_CONTEXTdeleted; Flutter moves to the "sends a context" list),backend/tests/unit/docs/test_deferred_sdk_pages.py,backend/tests/unit/showcase/test_site_walkthroughs.py(test renamedtest_video_4s_description_names_no_native_sdk_limit)frontend/src/content/videos.json(video 4's description; a site PR: T388, merges through the G5 train on the standing word, D454)The choices, copied from the iOS pattern in Dart:
EvaluationCache.get(user, key, {String? context})(null means no check) andset(..., {String context = ''}). The in-flight key isuser\u0000flag\u0000context.query: {'user_id': userId, if (context.isNotEmpty) 'context': context}; a Dart map keeps insertion order, souser_idcomes first. The context goes through_uriandUri.encodeQueryComponent, asuser_idalready does (no new encoder).EvalResult.disabled.json.encode, read back, and written again through aSplayTreeMapat every level, so the same attributes in another order (nested maps included) are one cache slot and one request.DateTime, NaN, a cycle):evaluateFlagreturnsEvalResult.disabled(key)before the cache, the dedupe and the offline store; nothing is sent, cached or logged, and the stored answer is not served.Network error: the request timed outorNetwork error: the request failed), no chained error or URI field is kept, and_uriis inside thetry, so an unparseable URL becomes the sameApiException._serverQuery(Uri)and_serverContext(Uri)read a recorded URL as the server does: split on&, each pair at its first=, thenUri.decodeQueryComponent(it reads+as a space), thenjson.decode.Merging main after iOS and Android (the rule recorded for this PR): take this PR's final state whole for the shared pages, the four claims files,
videos.jsonand the showcase test (both theDESCRIPTION_FACTSstring and the renamed test). Intest_documented_limits.pytake this side for theNATIVE_SDKSblock,_native_code,_CONTEXTand the native test, keep_COMMENT, and makeSENDSthe union of the iOS, Android and Flutter entries. Intest_deferred_sdk_pages.pySENDS_NO_CONTEXTlosesios,androidandflutter; keep every SDK's own numbered section and its..._on_the_<sdk>_pagestest. Afterwards:python scripts/doc_claims.py checkproblems 0, the two backend files andbackend/tests/unit/showcasegreen, andgrep -rn "only the user id"overdocs/,demo/andfrontend/src/contentfinds nothing.How it was verified
No Flutter or Dart toolchain was available on the builder's machine, so no Dart line or test has been run by anyone yet. CI's
flutterjob (Flutter 3.19.6) is the first compile and the first run of every Dart line here; the Dart was read as Dart 3 / Flutter 3.19 by the builder and by the reviewer, who found no compile error or run-time failure by reading.Measured at
d15bac5aunless another sha is given (records:handback-builder-A1-flutter,-flutter-2; reviewreview-a1-flutter, ate839f0e9):test_documented_limits.py,test_deferred_sdk_pages.py): 348 passed (main: 342; 3native[...]cases removed, 9 added).backend/tests/unit/docsandshowcasetogether: 5081 passed.python scripts/doc_claims.py check: problems 0.mkdocs build --strict: exit 0.ruff check/ruff format --checkon the pin file: clean. DCO ok for both commits. The secret scan: no findings.backend/ modules/ frontend/ pyproject.tomllists exactly the two backend test files,test_site_walkthroughs.pyandvideos.json; nothing undermodules/,.github/,scripts/orbackend/app, and nopyproject.toml.client_test.dartnow has 82 tests, so 101 are expected in CI (+31). The job result and the exact count come from CI.e839f0e9: the marker removed fromclient.dartfires 3 gates; a pinned Dart test renamed fires its pin; the old note put back firestest_the_old_flutter_note_is_gone_from_both_pages;flutterput back inSENDS_NO_CONTEXTfires 4 tests; Android's; Flutter sends only the user id to flagswording put back invideos.jsonfires the video test (1 failed, 57 passed; 58 passed restored).e839f0e9: the wide DB-free sweep gave2 failed, 25930 passed, 181 skipped, 168 errors; the same 170 ids fail onorigin/main(the 168 need PostgreSQL; the 2 are the pep440 pair,No module named 'packaging'). Not re-run atd15bac5a(docs text and one pin string changed).regression #438: isEnabled passes the attributes on, becauseisEnabledhas noattributes:on main), the context unencoded and%2Bwritten as+. Their results are not in yet.review-a1-flutterapprovede839f0e9with three optional nits;d15bac5aimplements the page-wording nit (N3) and has no review record of its own. The body carries the merge rule from nit N2.Checklist:
make lintclean: not run as a whole; ruff clean on the pin file; CI'sFrontend Testsmust show success at the final head before mergeNot verified: every Dart line and test; V3a's exact URL (
%7B%22q%22%3A%22a%2Bb%26c%3Dd%23e+f%C3%A9%22%7D, written fromencodeQueryComponent's rules and not measured); thatUri.parsethrows for a non-numeric port (the unparseable-URL test); NaN handling ofjson.encodeon Flutter web; a device; the real server; the frontend suite.Regression test
sdk/flutter/test/client_test.dart--regression #438: evaluateFlag sends the attributes as context after user_id,regression #438: a targeting rule on attributes matchesandregression #438: isEnabled passes the attributes onOn main's
client.dartandhttp_client.dartthe evaluate and rule tests fail on assertions (the path lacks&context=...; the rule does not match), and theisEnabledtest does not compile becauseisEnabledhas noattributes:there. That is the builder's and the reviewer's reading; the old-code plant branch is what runs it in CI.Risk and rollback
This changes the SDK's request to the public flag-evaluation route for callers that pass attributes, and removes a documented limit from the public docs. If it is wrong, flag calls with attributes answer from the wrong context or fail; revert this PR to undo it, which also restores the limitations row and the claims units. Nothing changes on the server, and no release is cut here. It merges after the iOS and Android PRs.
🤖 Generated with Claude Code
https://claude.ai/code/session_011kqtSDC7sd5ue3m6LuwdXV