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: Only fetch actions available to an entity during schema validation #1095

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions python/composio/client/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
TriggerType,
)
from composio.client.exceptions import ComposioClientError, ComposioSDKError
from composio.constants import PUSHER_CLUSTER, PUSHER_KEY
from composio.constants import DEFAULT_ENTITY_ID, PUSHER_CLUSTER, PUSHER_KEY
from composio.utils import help_msg, logging
from composio.utils.shared import generate_request_id

Comment on lines 33 to 39

Choose a reason for hiding this comment

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

Potential Issue: The addition of DEFAULT_ENTITY_ID to the import statement indicates a change in how entity IDs are managed across the codebase. This could potentially introduce a default value where it was previously optional or unspecified, affecting the behavior of entity-related operations.

Actionable Steps:

  • Review Usage: Check all instances where DEFAULT_ENTITY_ID is used to ensure it aligns with the intended logic and does not introduce unintended defaults.
  • Test Coverage: Ensure that test cases cover scenarios with and without the default entity ID to prevent regressions.
  • Documentation: Update any relevant documentation to reflect the introduction of a default entity ID, if applicable.

This change could have a broader impact on the system's behavior, especially if entity IDs are critical to the application's logic.


Expand Down Expand Up @@ -91,7 +91,7 @@ class ConnectedAccountModel(BaseModel):
connectionParams: AuthConnectionParamsModel

clientUniqueUserId: t.Optional[str] = None
entityId: t.Optional[str] = None
entityId: str = DEFAULT_ENTITY_ID

# Override arbitrary model config.
model_config: ConfigDict = ConfigDict( # type: ignore
Comment on lines 91 to 97

Choose a reason for hiding this comment

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

Refactor: The change from an optional entityId to a default value of DEFAULT_ENTITY_ID enhances consistency across the codebase. This aligns with the check_connected_account function, which now expects an entity_id parameter. This change ensures logical consistency and reduces potential errors related to missing entityId values.


Expand Down
9 changes: 6 additions & 3 deletions python/composio/tools/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def add_auth(
parameters=parameters,
)

def check_connected_account(self, action: ActionType) -> None:
def check_connected_account(self, action: ActionType, entity_id: str) -> None:
"""Check if connected account is required and if required it exists or not."""
action = Action(action)
if action.no_auth or action.is_runtime:
Expand All @@ -476,6 +476,7 @@ def check_connected_account(self, action: ActionType) -> None:
# Normalize app names/ids coming from API
connection.appUniqueId.upper()
for connection in self._connected_accounts
if connection.entityId == entity_id
]:
raise ComposioSDKError(
f"No connected account found for app `{action.app}`; "
Expand Down Expand Up @@ -582,7 +583,7 @@ def _execute_remote(
"""Execute a remote action."""
auth = self._custom_auth.get(App(action.app))
if auth is None:
self.check_connected_account(action=action)
self.check_connected_account(action=action, entity_id=entity_id)

entity = self.client.get_entity(id=entity_id)
output = entity._execute( # pylint: disable=protected-access
Expand Down Expand Up @@ -1057,7 +1058,9 @@ def get_action_schemas(
)
if check_connected_accounts:
for item in remote_items:
self.check_connected_account(action=item.name)
self.check_connected_account(
action=item.name, entity_id=self.entity_id
)
else:
warnings.warn(
"Not verifying connected accounts for apps."
Expand Down
8 changes: 5 additions & 3 deletions python/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def test_example(
), f"Please provide value for `{key}` for testing `{example['file']}`"

filepath = Path(example["file"])
original_source = filepath.read_text(encoding="utf-8")
code = filepath.read_text(encoding="utf-8")

if plugin_to_test != "lyzr":
Expand All @@ -226,10 +227,11 @@ def test_example(
# Wait for 2 minutes for example to run
proc.wait(timeout=180)

filepath.write_text(original_source, encoding="utf-8")

print(t.cast(t.IO[bytes], proc.stderr).read().decode(encoding="utf-8"))
# Check if process exited with success
assert proc.returncode == 0, (
t.cast(t.IO[bytes], proc.stderr).read().decode(encoding="utf-8")
)
assert proc.returncode == 0

# Validate output
output = (
Expand Down
Loading