-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: API Key Standardization with Backward Compatibility #1473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Reviewed everything up to fed8cbd in 2 minutes and 51 seconds
More details
- Looked at
189
lines of code in3
files - Skipped
0
files when reviewing. - Skipped posting
12
drafted comments based on config settings.
1. python/composio/client/__init__.py:444
- Draft comment:
Good integration of API key normalization in initiate_connection. The conversion of app_name to string and using normalize_api_key_params is clear. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
2. python/composio/client/collections.py:289
- Draft comment:
Swallowing exceptions in the normalization try/except block may hide issues. It might be helpful to log the exception to aid debugging. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50%
The suggestion to add error logging is reasonable since silently swallowing exceptions can hide issues. However, in this case, the code is designed to gracefully degrade - if parameter normalization fails, it just proceeds with unnormalized parameters. The error isn't critical since there's a valid fallback behavior. Adding logging would be nice-to-have but isn't strictly necessary for correct operation.
I may be underestimating the value of logging for debugging issues in production. Silent failures can make problems very hard to track down.
While logging would be helpful, the code's behavior is intentionally designed to proceed without normalization on failure. The comment doesn't identify a real bug or issue that needs fixing.
The comment should be deleted. While adding logging would be nice, the current behavior is intentional and the comment doesn't identify a critical issue that needs to be fixed.
3. python/composio/client/collections.py:1554
- Draft comment:
Similarly, in integrations.create the exception during app detail lookup is silently ignored. Consider logging the error to prevent hidden bugs. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50%
The code is silently catching all exceptions when trying to get app details for parameter normalization. While logging could help with debugging, the code is designed to gracefully continue without normalization if the lookup fails. The parameter normalization is an optional enhancement, not a critical requirement. The comment suggests adding complexity for a non-critical path.
The comment identifies a real issue with silent exception handling. Logging could help troubleshoot issues. However, I need to consider if this is important enough to warrant a code change.
Since parameter normalization is an optional enhancement and the code gracefully continues without it, adding logging complexity may not provide enough value to justify the change.
The comment should be deleted since it suggests adding complexity for an optional, non-critical code path that already handles failures gracefully.
4. python/composio/utils/param_normalization.py:55
- Draft comment:
The normalization utility is straightforward and well-documented. Ensure that any future changes to parameter mappings keep backward compatibility. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
5. python/composio/client/__init__.py:444
- Draft comment:
Good use of normalize_api_key_params. Converting app_name to string is safe if app_name might be non-string, but double-check that this conversion is needed in all cases. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
6. python/composio/client/collections.py:289
- Draft comment:
Consider logging the exception in the try/except block when fetching integration details for parameter normalization. Silently passing exceptions can make debugging harder. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
This is a reasonable suggestion - silently swallowing exceptions can make debugging harder. However, in this case, the code is designed to gracefully degrade - if parameter normalization fails, it's acceptable to proceed without it. The error isn't critical enough to warrant logging since the code has a valid fallback behavior. Adding logging here could create noise in the logs without providing much value.
I could be wrong about the importance of logging here - if parameter normalization failures are something that needs to be monitored or debugged frequently, having logs would be valuable.
While logging can be helpful, in this case the failure mode is well-understood and gracefully handled. The code is designed to work without parameter normalization, so logging these expected failures would likely just create noise.
The comment should be deleted. While adding logging is generally good practice, in this specific case the silent failure is intentional and appropriate since the code has a valid fallback behavior.
7. python/composio/client/collections.py:1553
- Draft comment:
In the integration creation flow, consider logging any exceptions during app name lookup instead of silently passing to help diagnose potential issues. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50%
The comment makes a reasonable suggestion to add logging for better debugging. However:
- The app name lookup is only used for optional parameter normalization
- If it fails, the code gracefully continues without normalization
- The failure is not a critical error that impacts core functionality
- The comment is more of a nice-to-have enhancement than fixing a real issue
The comment identifies a legitimate opportunity to improve debugging. Silent exception handling can make issues harder to diagnose.
While logging would be nice, this is an optional enhancement path where failure is expected and handled gracefully. The code works correctly without logging.
Delete the comment. While adding logging would be nice, the current code handles failures appropriately for this optional enhancement path. The comment doesn't identify a real issue that needs fixing.
8. python/composio/utils/param_normalization.py:55
- Draft comment:
The normalization function is concise and well-documented. Note that for 'demio' the mapping produces 'api_secret' rather than 'api_key'; ensure that downstream consumers handle this case appropriately. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
9. python/composio/client/collections.py:545
- Draft comment:
Typographical error: The docstring of _ChunkedTriggerEventData uses 'Cunked trigger event data model.'—please change 'Cunked' to 'Chunked'. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
10. python/composio/client/collections.py:342
- Draft comment:
Typographical error: In the AppAuthScheme docstring, 'App authenticatio scheme.' should be 'App authentication scheme.' - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
11. python/composio/client/collections.py:1110
- Draft comment:
Typographical error: In the SearchResultTask model, the field description contains 'Descrption of the subtask.'—please correct it to 'Description of the subtask.' - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
12. python/composio/client/collections.py:684
- Draft comment:
Typographical error: The docstring for the callback method in TriggerSubscription reads 'Register a trigger callaback.' Change 'callaback' to 'callback'. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
Workflow ID: wflow_6vyQaYgtdbsfTuMy
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
|
||
# Normalize parameters using the utility function | ||
params = normalize_api_key_params(app_name, params, auth_mode) | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding more specific exception handling and logging here. Catching a generic Exception silently could hide important issues. At minimum, log the error for debugging purposes.
:param auth_mode: Authentication mode (normalization only applies to "API_KEY" mode) | ||
:return: Dictionary with normalized parameter names | ||
""" | ||
if not app_name or not params: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a type check for params
to ensure it's actually a dictionary. While the type hint helps during development, a runtime check would prevent potential TypeErrors in production.
if app.appId == app_id: | ||
app_name = app.name | ||
break | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the other exception handler, this should include logging and more specific exception handling. Also, consider caching the app name lookup results to avoid repeated API calls for the same app_id.
Code Review SummaryOverall, this PR provides a solid implementation of API key parameter normalization with good backward compatibility support. Here's a detailed assessment: Strengths 👍
Areas for Improvement 🔧
Code Quality Rating: 7/10The implementation is solid and achieves its goals, but could be more robust with the suggested improvements in error handling and type safety. The changes are well-integrated and maintain backward compatibility effectively. Recommendations
The PR is acceptable to merge after addressing the critical comments about error handling and type safety. |
# Special case for Demio which has two parameters | ||
if "apiKey" in params and "api_key" not in params: | ||
normalized_params["api_key"] = params["apiKey"] | ||
|
||
if "apiSecret" in params and "api_secret" not in params: | ||
normalized_params["api_secret"] = params["apiSecret"] | ||
|
||
# Check for any known legacy parameter and map to api_key | ||
for legacy_param in LEGACY_API_KEY_PARAMS: | ||
if legacy_param in params and "api_key" not in params: | ||
normalized_params["api_key"] = params[legacy_param] | ||
break # Only use the first match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code handles apiKey
and apiSecret
as special cases, but these are also in LEGACY_API_KEY_PARAMS
. This creates inconsistent behavior where only the first match in the list will be used due to the break
statement.
LGTM 👍 |
if params is not None: | ||
# Get integration details to extract app name and auth mode | ||
integration = self.client.integrations.get(id=integration_id) | ||
if integration is not None: | ||
auth_mode = integration.authScheme | ||
|
||
# Normalize parameters using the utility function | ||
params = normalize_api_key_params(params, auth_mode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling for API calls was removed, which means any failures in getting integration or app details will now cause exceptions to propagate instead of being handled gracefully.
📝 Committable Code Suggestion
‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if params is not None: | |
# Get integration details to extract app name and auth mode | |
integration = self.client.integrations.get(id=integration_id) | |
if integration is not None: | |
auth_mode = integration.authScheme | |
# Normalize parameters using the utility function | |
params = normalize_api_key_params(params, auth_mode) | |
if params is not None: | |
try: | |
# Get integration details to extract app name and auth mode | |
integration = self.client.integrations.get(id=integration_id) | |
if integration is not None: | |
auth_mode = integration.authScheme | |
# Normalize parameters using the utility function | |
params = normalize_api_key_params(params, auth_mode) | |
except Exception: | |
# If we can't get integration details, proceed without normalizing | |
pass |
if auth_config is not None: | ||
app_name = None | ||
apps_collection = Apps(client=self.client) | ||
apps = apps_collection.get() | ||
for app in apps: | ||
if app.appId == app_id: | ||
app_name = app.name | ||
break | ||
|
||
# Normalize auth parameters if app name was found | ||
if app_name is not None: | ||
auth_config = normalize_api_key_params(auth_config, auth_mode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the first issue, error handling was removed from the app lookup code, which means any failures in getting app details will now cause exceptions to propagate.
📝 Committable Code Suggestion
‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if auth_config is not None: | |
app_name = None | |
apps_collection = Apps(client=self.client) | |
apps = apps_collection.get() | |
for app in apps: | |
if app.appId == app_id: | |
app_name = app.name | |
break | |
# Normalize auth parameters if app name was found | |
if app_name is not None: | |
auth_config = normalize_api_key_params(auth_config, auth_mode) | |
if auth_config is not None: | |
app_name = None | |
try: | |
# Get app details to extract app name | |
apps_collection = Apps(client=self.client) | |
apps = apps_collection.get() | |
for app in apps: | |
if app.appId == app_id: | |
app_name = app.name | |
break | |
except Exception: | |
# If we can't find the app name, proceed without normalizing | |
pass | |
# Normalize auth parameters if app name was found | |
if app_name is not None: | |
auth_config = normalize_api_key_params(auth_config, auth_mode) |
Overview
This PR implements API key field name standardization across the codebase with backward compatibility. It introduces a parameter normalization system that transparently converts legacy parameter names to the standardized
api_key
name.Changes
Created a utility module in
python/composio/utils/param_normalization.py
with:PARAMETER_MAPPINGS
dictionary containing mappings for ~40 appsnormalize_api_key_params
function that only applies normalization for "API_KEY" auth modeUpdated
python/composio/client/__init__.py
to use this utility in theinitiate_connection
methodUpdated
python/composio/client/collections.py
to apply normalization in:Integrations.create
methodConnectedAccounts.initiate
methodImportant
Standardizes API key field names with backward compatibility using a new parameter normalization system applied in key methods.
normalize_api_key_params
inparam_normalization.py
to standardize API key field names.initiate_connection
in__init__.py
andcreate
incollections.py
to use normalization.param_normalization.py
withPARAMETER_MAPPINGS
for ~40 apps.api_key
.This description was created by
for fed8cbd. It will automatically update as commits are pushed.