Skip to content

feat!: Return private attributes as a Set - #476

Merged
keelerm84 merged 6 commits into
feat/9.xfrom
mk/SDK-84/private-attribute-sets
Nov 3, 2026
Merged

keelerm84 merged 6 commits into
feat/9.xfrom
mk/SDK-84/private-attribute-sets

Conversation

@keelerm84

@keelerm84 keelerm84 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Config#private_attributes now returns a Set of attribute reference
strings instead of an Array. The :private_attributes option still
accepts any Enumerable, and the SDK converts it to a Set.

LDContext#private_attributes now returns a frozen Set of Reference
objects instead of an Array. The context already stored a Set
internally and copied it to an Array on every call. Private attributes
have no meaningful order or duplicates, so a Set is the correct type.

Code that indexes into the result or calls Array-only methods on it
must change. LDContext#to_h and #to_json still emit privateAttributes
as an Array, so serialized contexts and event payloads do not change.


Note

Overview
Breaking change: Config#private_attributes and LDContext#private_attributes now expose frozen Sets instead of arrays. The :private_attributes config option still accepts any Enumerable and is normalized (deduped) into a set; context _meta.privateAttributes may be an array or a set when building a context.

LDContext stops copying its internal set to an array on every read, and equality checks use set comparison directly. ContextFilter stores global private refs in a set and merges them with context refs via set union (|). Reference.create is idempotent when passed an existing Reference.

Serialized context output is unchanged: hash_single_kind still emits privateAttributes as an array via .to_a.

Reviewed by Cursor Bugbot for commit 4de0ad6. Bugbot is set up for automated code reviews on this repo. Configure here.

Config#private_attributes now returns a Set of attribute reference
strings instead of an Array. The :private_attributes option still
accepts any Enumerable, and the SDK converts it to a Set.

LDContext#private_attributes now returns a frozen Set of Reference
objects instead of an Array. The context already stored a Set
internally and copied it to an Array on every call. Private attributes
have no meaningful order or duplicates, so a Set is the correct type.

Code that indexes into the result or calls Array-only methods on it
must change. LDContext#to_h and #to_json still emit privateAttributes
as an Array, so serialized contexts and event payloads do not change.
@keelerm84
keelerm84 marked this pull request as ready for review November 2, 2026 16:51
@keelerm84
keelerm84 requested a review from a team as a code owner November 2, 2026 16:51
@kinyoklion

Copy link
Copy Markdown
Member

I think we need to freeze the private_attributes set on the config maybe.

@kinyoklion

Copy link
Copy Markdown
Member

I do have some concerns that you cannot access this property and then feed it directly back into a context without causing a problem.

Config#private_attributes now returns a Set. Without the freeze, a caller can change the set after the client starts, and the event processor reads the changed set. LDContext#private_attributes is already frozen, so this makes the two match.
Config#private_attributes now returns a Set, but LDContext.create rejected any privateAttributes value that was not an Array. Passing the config value into a context made an invalid context. LDContext.create now accepts an Array or a Set.
LDContext#private_attributes returns a Set of Reference objects. Reference.create accepted only a String or a Symbol, so passing those references into a new context made each one an empty reference, and the SDK dropped them. Reference.create now returns a Reference argument unchanged. A Reference is immutable, so it is safe to share. This also lets Config accept references in private_attributes.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 228d01e. Configure here.

Comment thread lib/ldclient-rb/context.rb Resolved
context_spec.rb loads only ldclient-rb/context, so the spec failed with NameError when the file ran alone. A Set literal tests the same path.
@keelerm84
keelerm84 merged commit 4589786 into feat/9.x Nov 3, 2026
10 checks passed
@keelerm84
keelerm84 deleted the mk/SDK-84/private-attribute-sets branch November 3, 2026 12:59
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.

2 participants