Open
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a monkey patch for the IndexClient._get method from the indexclient library to automatically inject authentication parameters when they are missing from requests. The patch ensures that calls to _get() will use self.auth as a fallback when no explicit auth parameter is provided, preventing authentication failures due to missing credentials.
Key changes:
- Implements a monkey patch function that wraps the original
IndexClient._getmethod - Automatically sets
auth=self.authwhen theauthparameter is omitted from method calls - Applies the patch during module initialization
|
|
||
| def patched__get(self, *args, **kwargs): | ||
| """Patch to ensure 'auth' is set and log the call.""" | ||
| if 'auth' not in kwargs: |
There was a problem hiding this comment.
The patch assumes that self.auth exists and is valid. Consider adding a check to ensure self.auth is not None before assigning it, or handle the case where it might not be available.
Suggested change
| if 'auth' not in kwargs: | |
| if 'auth' not in kwargs: | |
| if self.auth is None: | |
| raise ValueError("self.auth is not set. Ensure it is initialized before calling _get.") |
matthewpeterkort
approved these changes
Sep 25, 2025
Collaborator
matthewpeterkort
left a comment
There was a problem hiding this comment.
Working on development
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TL/DR
This PR:
🛠 PR #8: Monkey Patch
IndexClient._getto Ensure Auth Header🔍 Summary
This PR introduces a monkey patch to the
IndexClient._getmethod in theindexclientPython library to ensure that every_get()request includes the requiredauthparameter. This patch helps prevent unauthenticated requests when the caller forgets to passauthexplicitly.📚 Use Case
In the
image_viewerapplication (or its backend), theIndexClient._get()method from theindexclientlibrary is used to retrieve metadata from Gen3's Indexd service. However, the base method requires the caller to manually supply theauthparameter.Forgetting to pass
authresults in failed requests or hard-to-debug authentication issues. This monkey patch injectsself.authautomatically if it's missing, ensuring consistent authenticated requests.✅ Acceptance Criteria
IndexClient._getwith a wrapped version (patched__get) at runtime.authkeyword argument, setauth=self.authautomatically._getwhenauthis provided.monkey_patch_indexclient__get()is called at the end of the file).🧪 Acceptance Tests
Manual verification steps:
Without patch:
IndexClient._get(...)withoutauth=With patch:
auth=self.auth.Explicit auth override:
_get(..., auth=some_other_auth)some_other_authis used, notself.auth.