Skip to content
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

fix: connected account bugfix #1365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/composio/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def get_connection(
creation_date = datetime.fromisoformat(
connected_account.createdAt.replace("Z", "+00:00")
)
if latest_account is None or creation_date > latest_creation_date:
if latest_account is None or creation_date < latest_creation_date:
Comment on lines 342 to +345

Choose a reason for hiding this comment

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

The logic for finding the latest account is incorrect - using < will return the oldest account instead of newest. Should use > to get most recent creation_date.

📝 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.

Suggested change
creation_date = datetime.fromisoformat(
connected_account.createdAt.replace("Z", "+00:00")
)
if latest_account is None or creation_date > latest_creation_date:
if latest_account is None or creation_date < latest_creation_date:
creation_date = datetime.fromisoformat(
connected_account.createdAt.replace("Z", "+00:00")
)
if latest_account is None or creation_date > latest_creation_date:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The variable names latest_account and latest_creation_date are misleading since we're actually tracking the earliest account. Consider renaming these to earliest_account and earliest_creation_date to better reflect their purpose.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Consider adding a clarifying comment above this line to explain the logic:

# Find the earliest connected account based on creation date

This will help future developers understand the intention of this comparison.

Copy link
Contributor

Choose a reason for hiding this comment

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

The condition is reversed. Using '<' here will select the oldest account, not the latest. For the intended behavior, it should be 'creation_date > latest_creation_date'.

Suggested change
if latest_account is None or creation_date < latest_creation_date:
if latest_account is None or creation_date > latest_creation_date:

latest_creation_date = creation_date
latest_account = connected_account

Expand Down