Skip to content

Conversation

jonathannorris
Copy link
Member

Summary

Extends OpenFeature evaluation context user identification to support userId as a third option alongside existing targeting_key and user_id support.

Changes

  • Enhanced user ID resolution with priority: targeting_key > user_id > userId
  • Improved attribute filtering to exclude all user ID types (user_id, userId, targeting_key) from custom data
  • Updated error messages to include userId in user identification failure messages
  • Code cleanup - consolidated user ID exclusion logic into single efficient statement

Testing

  • ✅ Added comprehensive tests for userId priority and exclusion behavior
  • ✅ Enhanced existing test coverage for user ID mapping edge cases
  • ✅ All existing tests continue to pass

Backward Compatibility

  • ✅ Fully backward compatible - existing targeting_key and user_id behavior unchanged
  • ✅ Only adds new functionality for userId attribute support

This change improves OpenFeature integration flexibility while maintaining consistent user identification behavior across all three supported user ID sources.


Open Background Agent:
Web · Cursor

[Slack Thread](https://taplytics.slack.com/archives/C02DU5GTB6U/p1752872862815949%3Fthread_ts=1752872862.815949

cursoragent and others added 2 commits July 21, 2025 20:44
Co-authored-by: jonathan <jonathan@taplytics.com>
Co-authored-by: jonathan <jonathan@taplytics.com>
Copilot

This comment was marked as outdated.

… exclusion logic, include targeting_key

- Remove unused user_id_source variable and assignments (addresses code clutter concern)
- Consolidate user ID exclusion logic into single efficient statement
- Include targeting_key in exclusion logic to prevent it from being added to custom data
- Update comment to mention all three user ID types for clarity
- Add comprehensive test coverage for targeting_key exclusion from attributes
- Split user ID validation into two distinct error cases:
  1. Missing user ID (no valid targeting_key, user_id, or userId found)
  2. Invalid type (user ID found but not a string)
- Include original field name in type validation error for better debugging
- Re-introduce user_id_source variable for error reporting purposes only
- Enhanced error specificity: 'targeting_key must be a string, got int' vs generic message
…convention

- Rename test functions from camelCase to snake_case:
  - test_create_user_from_context_with_userId → test_create_user_from_context_with_user_id_attribute
  - test_create_user_from_context_userId_excluded_when_used → test_create_user_from_context_user_id_attr_excluded_when_used
  - test_create_user_from_context_invalid_userId_types → test_create_user_from_context_invalid_user_id_attr_types
  - test_resolve_details_with_userId_priority → test_resolve_details_with_user_id_attr_priority

- Rename variables from camelCase to snake_case:
  - userId → user_id_attr (to avoid confusion with user_id)

- Remove unused variable assignments in test_provider.py
- Fix whitespace and trailing whitespace issues
- Merged 6 user model tests into 2 comprehensive tests:
  1. test_create_user_from_context_with_user_id_attribute: covers userId functionality, priority order, and error cases
  2. test_create_user_from_context_user_id_exclusion: covers all user ID field exclusion scenarios

- Removed redundant provider test since core logic is tested in user model

- Maintained full test coverage while significantly reducing test count
- All tests passing with same functionality coverage
- Applied Black formatter to test files to pass CI formatting checks
- All tests still passing after formatting
- Resolves 'Check formatting' CI failure
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends OpenFeature evaluation context user identification to support userId as a third option for user identification, alongside the existing targeting_key and user_id support. The implementation maintains a clear priority hierarchy and ensures backward compatibility.

  • Enhanced user ID resolution with priority: targeting_key > user_id > userId
  • Updated attribute filtering to exclude all user ID types from custom data
  • Improved error messages to include all supported user ID sources

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
devcycle_python_sdk/models/user.py Added userId attribute support in user creation logic with priority handling and updated exclusion filtering
test/models/test_user.py Added comprehensive test coverage for userId functionality, priority order, and exclusion behavior
Comments suppressed due to low confidence (1)

devcycle_python_sdk/models/user.py:130

  • [nitpick] The error message format is inconsistent with the previous error message style. Consider maintaining consistency by using the same prefix format: 'DevCycle: Evaluation context...' or create a more user-friendly message that doesn't expose internal variable names.
                f"DevCycle: {user_id_source} must be a string, got {type(user_id).__name__}"

Comment on lines 109 to +127
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"

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"
)

Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

[nitpick] The user_id_source variable is only used for error messages when type validation fails. Consider initializing it closer to where it's used or using a more descriptive approach like extracting the source determination into a separate method to improve code clarity.

Copilot uses AI. Check for mistakes.

@jonathannorris jonathannorris merged commit aaf40b9 into main Jul 22, 2025
13 checks passed
@jonathannorris jonathannorris deleted the cursor/update-openfeature-user-id-mapping-080b branch July 22, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants