Skip to content

feat: add updateAttributes to merge into the existing attributes - #188

Open
vazarkevych wants to merge 1 commit into
fix/remote-eval-flowfrom
feature/update-attributes
Open

vazarkevych wants to merge 1 commit into
fix/remote-eval-flowfrom
feature/update-attributes

Conversation

@vazarkevych

@vazarkevych vazarkevych commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds updateAttributes / updateAttributesAsync, which merge into the existing attributes instead of replacing them. Split out of #176 (section 1).

Depends on #187 — this branch is built on it; only the last commit belongs to this PR.

API Behavior
setAttributes / setAttributesAsync replace: anything not included is dropped (unchanged)
updateAttributes / updateAttributesAsync merge: new keys added, existing overwritten, untouched preserved

Why: adding one attribute (e.g. after login) meant rebuilding the whole map, and a key left out was silently dropped.

Behavior

Same as updateAttributes in the JS SDK (GrowthBook.ts): a shallow merge, then the regular setAttributes path. So sticky bucket refresh and, in remote-eval mode, the fresh evaluation from #187 apply unchanged; the async variant awaits both.

  • The merge is shallow: a nested Map or List replaces the previous value of that key.
  • A null value is stored as null; it does not remove the key.
  • The caller's Map is not modified.

setAttributes now documents that it is a full replace and points to updateAttributes.

Compatibility

Additive only: no existing API or behavior changes.

Test plan

  • 13 new tests. 11 in gb_sdk_attributes_test.dart: merge, overwrite, merge vs replace, empty map, null values, shallow merge, bucketing on merged attributes, caller's Map untouched, accumulation, async variant, sticky bucket refresh awaited. 2 in gb_sdk_remote_eval_test.dart: the remote-eval POST carries the merged attributes, for both variants.
  • 10 of the new tests fail if the merge is replaced by a plain replace; the other 3 cover properties a replace also has.
  • Against Flutter 3.27.0 (the CI version): dart analyze --fatal-infos, dart format and flutter test (3 runs) clean.
  • Manual check against a GrowthBook Proxy with remote evaluation and streaming: updateAttributes({'country': 'UA'}) sent a POST with {id, country}, kept the id-based experiment assignment, and a later published change still arrived through the stream with the merged attributes.

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.

1 participant