Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 3, 2025

Problem

When calling list_users2() from the UsersV2Api, the custom_attributes field was not accessible on the returned User objects, even though the OneLogin API includes this data in responses. Users had to resort to workarounds like:

# Workaround - accessing raw data
response = user_instance.list_users2_with_http_info(
    fields="id,email,custom_attributes"
).raw_data

This issue occurred because the custom_attributes field was not defined in the User model (onelogin/models/user.py).

Solution

Added custom_attributes as an optional dictionary field to the User model. Custom attributes are dynamic key-value pairs defined per OneLogin account, so they're represented as Optional[Dict[str, Any]].

Changes:

  • Added custom_attributes field to the User model with proper type annotations
  • Updated the __properties list to include the new field
  • Modified from_dict() to parse custom_attributes from API responses
  • Added documentation for the field in docs/User.md
  • Created comprehensive test suite to validate the implementation

Usage

After this fix, custom attributes are directly accessible:

users = user_instance.list_users2()
for user in users:
    if user.custom_attributes:
        employee_id = user.custom_attributes.get('employee_id')
        department = user.custom_attributes.get('department_code')
        cost_center = user.custom_attributes.get('cost_center')

Testing

  • ✅ All 335 existing tests pass (no regressions)
  • ✅ Added 4 new tests specifically for custom_attributes functionality
  • ✅ Validated with both UsersV1Api and UsersV2Api compatibility
  • ✅ Manual testing confirms proper serialization and deserialization

Fixes #107

Original prompt

This section details on the original issue you should resolve

<issue_title>custom_attributes not working with UsersV2Api</issue_title>
<issue_description>Hi,

When executing the examples 'user_instance.list_users2()' it does not provide the 'custom_attributes'.

The only way I manage to get these is with 'user_instance.list_users2_with_http_info(fields="id,email,custom_attributes").raw_data'.

I noticed custom_attributes is not defined in models/user.py, so probably related to this?</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #109

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
Copilot AI changed the title [WIP] custom_attributes not working with UsersV2Api Add custom_attributes field support to User model Oct 3, 2025
Copilot AI requested a review from Subterrane October 3, 2025 13:06
@Subterrane Subterrane marked this pull request as ready for review October 3, 2025 13:24
@Subterrane Subterrane requested a review from Copilot October 3, 2025 13:24
Copy link
Contributor

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 adds support for the custom_attributes field to the User model to resolve an issue where users could not access custom attributes from the UsersV2Api responses despite the data being present in the API response.

  • Added custom_attributes as an optional dictionary field to the User model
  • Updated serialization/deserialization methods to handle the new field
  • Created comprehensive test suite to validate the implementation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
onelogin/models/user.py Added custom_attributes field with proper type annotations and updated serialization methods
docs/User.md Added documentation for the new custom_attributes field
test/test_user_custom_attributes.py Added comprehensive test suite covering various scenarios for custom_attributes functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Subterrane Subterrane merged commit 3853ad8 into main Oct 3, 2025
7 checks passed
@Subterrane Subterrane deleted the copilot/fix-7dfdb782-e53a-4e01-bdb9-5a6a639884ab branch October 3, 2025 13: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.

custom_attributes not working with UsersV2Api Pypi does not provide version 3.2.1

2 participants