-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Update OpenFeature User ID Mapping to Support userId Attribute
#91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jonathannorris
merged 7 commits into
main
from
cursor/update-openfeature-user-id-mapping-080b
Jul 22, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
330a3d6
Support userId as alternative user ID source in DevCycle user creation
cursoragent 12c04b2
Exclude user_id and userId from custom data in all cases
cursoragent fb2408f
Address PR review feedback: remove unused user_id_source, consolidate…
jonathannorris 4c0eee6
Improve error messages: split validation and include field name
jonathannorris ac20967
Fix lint errors: rename functions and variables to follow snake_case …
jonathannorris 3110860
Consolidate tests: reduce from 7 to 2 comprehensive tests
jonathannorris 46771d3
Fix Black code formatting
jonathannorris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,30 +101,42 @@ def create_user_from_context( | |
| ) -> "DevCycleUser": | ||
| """ | ||
| Builds a DevCycleUser instance from the evaluation context. Will raise a TargetingKeyMissingError if | ||
| the context does not contain a valid targeting key or user_id attribute | ||
| the context does not contain a valid targeting key, user_id, or userId attribute | ||
|
|
||
| :param context: The evaluation context to build the user from | ||
| :return: A DevCycleUser instance | ||
| """ | ||
| user_id = None | ||
| user_id_source = None | ||
|
|
||
| if context: | ||
| if context.targeting_key: | ||
| user_id = context.targeting_key | ||
| user_id_source = "targeting_key" | ||
| elif context.attributes and "user_id" in context.attributes.keys(): | ||
| user_id = context.attributes["user_id"] | ||
| user_id_source = "user_id" | ||
| elif context.attributes and "userId" in context.attributes.keys(): | ||
| user_id = context.attributes["userId"] | ||
| user_id_source = "userId" | ||
jonathannorris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if not user_id or not isinstance(user_id, str): | ||
| if not user_id: | ||
| raise TargetingKeyMissingError( | ||
| "DevCycle: Evaluation context does not contain a valid targeting key or user_id attribute" | ||
| "DevCycle: Evaluation context does not contain a valid targeting key, user_id, or userId attribute" | ||
| ) | ||
|
|
||
|
Comment on lines
109
to
+127
|
||
| if not isinstance(user_id, str): | ||
| raise TargetingKeyMissingError( | ||
| f"DevCycle: {user_id_source} must be a string, got {type(user_id).__name__}" | ||
| ) | ||
|
|
||
| user = DevCycleUser(user_id=user_id) | ||
| custom_data: Dict[str, Any] = {} | ||
| private_custom_data: Dict[str, Any] = {} | ||
| if context and context.attributes: | ||
| for key, value in context.attributes.items(): | ||
| if key == "user_id": | ||
| # Skip user_id, userId, and targeting_key - these are reserved for user ID mapping | ||
| if key in ("user_id", "userId", "targeting_key"): | ||
| continue | ||
|
|
||
| if value is not None: | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.