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 14 commits into
base: master
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions python/composio/client/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Trigger,
TriggerType,
)
from composio.constants import PUSHER_CLUSTER, PUSHER_KEY
from composio.constants import DEFAULT_ENTITY_ID, PUSHER_CLUSTER, PUSHER_KEY
from composio.exceptions import (
ErrorFetchingResource,
InvalidParams,
Expand Down Expand Up @@ -92,7 +92,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 92 to 98

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
7 changes: 5 additions & 2 deletions python/composio/tools/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,9 @@ def _validate_connection_ids(
return valid
raise InvalidConnectedAccount(f"Invalid connected accounts found: {invalid}")

def check_connected_account(self, action: ActionType) -> None:
def check_connected_account(
Copy link
Contributor

Choose a reason for hiding this comment

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

The new parameter entity_id is added to check_connected_account but the docstring hasn’t been updated. Please document the new parameter.

self, action: ActionType, entity_id: t.Optional[str] = None
) -> 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 @@ -1677,6 +1679,7 @@ def check_connected_account(self, action: ActionType) -> None:
if action.app not in [
connection.appUniqueId.upper() # Normalize app names/ids coming from API
for connection in self._connected_accounts
if entity_id is None or connection.clientUniqueUserId == entity_id
]:
raise ConnectedAccountNotFoundError(
f"No connected account found for app `{action.app}`; "
Expand Down Expand Up @@ -1790,7 +1793,7 @@ def _execute_remote(
action=action
)
if auth is None:
self.check_connected_account(action=action)
self.check_connected_account(action=action, entity_id=entity_id)

output = self.client.get_entity( # pylint: disable=protected-access
id=entity_id
Expand Down
7 changes: 4 additions & 3 deletions python/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,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 @@ -236,10 +237,10 @@ def test_example(
# Wait for 2 minutes for example to run
proc.wait(timeout=180)

filepath.write_text(original_source, 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