You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds the ability to share an OpenAPIService instance between multiple RapidataClient instances, enabling connection pool reuse. This is a valuable feature for preventing resource exhaustion when creating multiple clients.
Code Quality & Best Practices
✅ Strengths
Clean implementation: The changes are minimal and non-breaking, properly using an optional parameter
Good documentation: The docstring clearly explains the purpose and usage of the openapi_service parameter
Consistent with project style: Uses from __future__ import annotations and proper type hints as per CLAUDE.md guidelines
Proper encapsulation: Exposes openapi_service as a read-only property, preventing accidental modifications
🔍 Observations
Export in __init__.py: The PR exports OpenAPIService from the main package. While this makes it accessible for sharing, it exposes an internal implementation detail that wasn't previously part of the public API. Consider whether this is intentional or if documentation should guide users on this pattern.
Environment mismatch handling: When reusing an openapi_service, the code checks openapi_service.environment != "rapidata.ai" to disable OTLP logging. However, there's no validation that the passed openapi_service has compatible settings (environment, oauth_scope, cert_path, etc.) with any other parameters provided.
Potential Issues
⚠️ Parameter Validation
When openapi_service is provided, the other authentication parameters (client_id, client_secret, environment, oauth_scope, cert_path, token, leeway) are ignored. This could lead to confusion if users provide both. Consider adding validation warnings.
🔒 Thread Safety Consideration
The connection pool (httpx Limits set to 200 max connections in rest.py:243) is shared when reusing an OpenAPIService. This is generally fine for httpx clients, but users should be aware that:
The shared session handles token refresh internally (OAuth2Client)
Multiple clients using the same service will share the same token refresh mechanism
This is likely the desired behavior, but should be documented
Performance Considerations
✅ Positive impact: The main benefit of this PR is realized. Sharing connection pools prevents:
Opening excessive connections when creating multiple clients
Resource exhaustion from too many file descriptors
Overhead of repeated TLS handshakes
Security Concerns
⚠️ Token Sharing
When sharing an OpenAPIService, all RapidataClient instances share the same OAuth token and credentials. This means:
All clients will authenticate as the same user/service
Token refresh affects all clients simultaneously
Credential resets affect all clients
This is likely intentional, but should be documented clearly.
Test Coverage
⚠️ Missing Tests
No tests were added for this functionality. Consider adding tests for:
Creating multiple clients with a shared openapi_service
Verifying that the openapi_service property returns the correct instance
Testing that shared clients properly reuse connections
Validating behavior when both openapi_service and auth parameters are provided
Recommendations
Add validation: Warn users if they provide both openapi_service and conflicting auth parameters
Add tests: Cover the new functionality with unit tests
Documentation: Consider adding an example in the docstring or README showing the recommended pattern for creating multiple clients
Type checking: Run uv run pyright src/rapidata/rapidata_client to ensure no type errors were introduced (as per CLAUDE.md guidelines)
Conclusion
This is a solid addition that solves a real problem (connection pool exhaustion) with minimal changes. The implementation is clean and follows project conventions. With the addition of parameter validation warnings and test coverage, this would be production-ready.
Recommendation: Approve with suggested improvements (non-blocking)
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.
No description provided.