Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Fix type validation errors in OneLogin Python SDK

Issues Fixed:

  • Fix manager_user_id type validation in User model to accept integers from API
  • Fix get_auth_factors return type to handle list response from API
  • Add/update tests to verify the fixes
  • Run tests to validate changes (10 fix tests + 339 existing tests pass)
  • Run code review
  • Run CodeQL security check (0 alerts)
  • Address PR review comments

Changes Made:

  1. ✅ Added field validator to User model to convert integer manager_user_id to string (mode='before')
  2. ✅ Updated get_auth_factors API method return type from GetAuthFactors200Response to List[GetAuthFactors200Response]
  3. ✅ Updated response_types_map for get_auth_factors to expect a list
  4. ✅ Added test for integer manager_user_id conversion
  5. ✅ Added comprehensive tests for get_auth_factors list response
  6. ✅ Improved docstring for manager_user_id validator to document None handling
  7. ✅ Added integration test for get_auth_factors API method with mocked response
  8. ✅ All tests pass successfully (10 fix-specific tests + 339 existing tests)
  9. ✅ CodeQL security scan: 0 alerts

Security Summary:

No security vulnerabilities were introduced or detected in this change. CodeQL analysis completed successfully with 0 alerts.

Original prompt

This section details on the original issue you should resolve

<issue_title>Type error in multiple functions</issue_title>
<issue_description>Hi,

I am not able to use some functions due to stricter type parsing. Here are two examples:

  1. user_res = user_instance.get_user2(user_id=user_id)
    Error:
    1 validation error for User manager_user_id Input should be a valid string [type=string_type, input_value=xxxx, input_type=int] For further information visit https://errors.pydantic.dev/2.12/v/string_type

  2. mfa_res = mfa_instance.get_auth_factors(user_id=user_id)
    Error:
    1 validation error for GetAuthFactors200Response Input should be a valid dictionary or instance of GetAuthFactors200Response [type=model_type, input_value=[{'factor_id': 3098, 'nam...actor_name': 'YubiKey'}], input_type=list] For further information visit https://errors.pydantic.dev/2.12/v/model_type

There might be more examples.</issue_description>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 27, 2026 13:59
- Add field validator to convert integer manager_user_id to string
- Update get_auth_factors return type from single object to List
- Add comprehensive tests for both fixes

Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix type errors in multiple functions Fix type validation errors in User model and get_auth_factors API Jan 27, 2026
Copilot AI requested a review from Subterrane January 27, 2026 14:05
@Subterrane Subterrane requested a review from Copilot January 27, 2026 15:33
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 fixes type validation errors in the OneLogin Python SDK that occur when the API returns data in formats not matching the model's strict type expectations.

Changes:

  • Added a field validator to the User model to handle manager_user_id values returned as integers by converting them to strings
  • Updated the get_auth_factors method to return a list of GetAuthFactors200Response objects instead of a single object, matching the actual API response format
  • Added comprehensive test coverage for both fixes

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
onelogin/models/user.py Added mode='before' validator to coerce integer manager_user_id to string
onelogin/api/multi_factor_authentication_api.py Changed return type from single object to list for get_auth_factors method
test/test_user_manager_user_id_fix.py Added test case for integer manager_user_id conversion
test/test_get_auth_factors_fix.py Added comprehensive test coverage for list-based auth factors response

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@field_validator('manager_user_id', mode='before')
@classmethod
def manager_user_id_to_string(cls, value):
"""Converts manager_user_id to string if it's an integer"""
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

The docstring should specify that this validator also handles None values by returning them unchanged, as this is important behavior documented in the code.

Suggested change
"""Converts manager_user_id to string if it's an integer"""
"""Converts manager_user_id to string if it's an integer and returns None values unchanged"""

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the docstring in commit 13d87c2 to document that None values are returned unchanged.

Comment on lines +32 to +37
def test_get_auth_factors_list_response(self):
"""
Test that GetAuthFactors200Response can be deserialized from a list.
This test validates the fix where API returns a list of factors
but model expected a single object.
"""
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

This test validates model deserialization but doesn't test the actual get_auth_factors API method. Consider adding an integration test that verifies the method returns List[GetAuthFactors200Response] when called with a mocked API response.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an integration test in commit 13d87c2 that verifies the get_auth_factors method returns List[GetAuthFactors200Response] with a mocked API response. The test also validates that the response_types_map is correctly set to 'List[GetAuthFactors200Response]'.

@Subterrane
Copy link
Contributor

@copilot Address PR comments, please.

- Improve docstring for manager_user_id validator to mention None handling
- Add integration test for get_auth_factors API method with mocked response

Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 27, 2026

@copilot Address PR comments, please.

Both PR comments have been addressed in commit 13d87c2:

  1. Improved docstring for manager_user_id validator to document None handling
  2. Added integration test for get_auth_factors API method with mocked response

All 10 fix-specific tests pass.

@Subterrane Subterrane marked this pull request as ready for review January 27, 2026 18:01
@Subterrane Subterrane merged commit a2991a8 into main Jan 27, 2026
3 of 6 checks passed
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.

Type error in multiple functions

2 participants