Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ def _all_records_subset_query(request: Request) -> Dict[str, Any]:
def _subset_or_query(request: Request, key: str) -> Optional[str]:
res = None
if request.body:
sub_res = _all_records_subset_query(request).get(key)
if sub_res:
res = str(sub_res)
# Only use all_records_subset_query when all_records is true
try:
attributes = request.body.get("data", {}).get("attributes", {})
if attributes.get("all_records", False):
sub_res = _all_records_subset_query(request).get(key)
if sub_res:
res = str(sub_res)
except AttributeError:
# data may be a list
pass
if not res and request.query:
res = request.query.get(key)
if res:
Expand Down
75 changes: 75 additions & 0 deletions src/agent_toolkit/tests/resources/actions/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,3 +1034,78 @@ def test_execute_should_get_all_form_fields_included_hidden(self):
response.body,
'{"success": "hidden_value"}',
)

def test_execute_should_ignore_all_records_subset_query_filters_when_all_records_is_false(self):
"""Test that when all_records is false, filters from all_records_subset_query are ignored."""
collected_filter = None

async def execute_with_filter_capture(ctx, rb):
nonlocal collected_filter
collected_filter = ctx.filter
return rb.success("done")

self.decorated_collection_book.add_action(
"test_bulk_action",
{
"scope": ActionsScope.BULK,
"execute": execute_with_filter_capture,
},
)

body_params = {
"data": {
"attributes": {
"values": {},
"ids": ["1", "2"],
"collection_name": "Book",
"parent_collection_name": None,
"parent_collection_id": None,
"parent_association_name": None,
"all_records": False,
"all_records_subset_query": {
"fields[Book]": "id,name,cost",
"page[number]": 1,
"page[size]": 15,
"sort": "-id",
"timezone": "Europe/Paris",
# This filter should be IGNORED when all_records is false
"filters": '{"field":"id","operator":"greater_than","value":"100"}',
},
"all_records_ids_excluded": [],
"smart_action_id": "Book-test_bulk_action",
"signed_approval_request": None,
},
"type": "custom-action-requests",
}
}

request = ActionRequest(
method=RequestMethod.POST,
action_name="test_bulk_action",
collection=self.decorated_collection_book,
body=body_params,
query={
"timezone": "Europe/Paris",
"collection_name": "Book",
"action_name": 0,
"slug": "test_bulk_action",
},
headers={},
user=self.mocked_caller,
client_ip="127.0.0.1",
)

response = self.loop.run_until_complete(self.action_resource.execute(request))
self.assertEqual(response.status, 200)

# The filter should NOT contain the "greater_than" condition from all_records_subset_query
# It should only contain the ID match condition for ids [1, 2]
self.assertIsNotNone(collected_filter)
if collected_filter.condition_tree:
filter_str = str(collected_filter.condition_tree)
# Should not contain the greater_than filter from all_records_subset_query
self.assertNotIn("greater_than", filter_str.lower())
self.assertNotIn(">", filter_str)
# Should contain the selected IDs (1 and 2)
self.assertIn("1", filter_str)
self.assertIn("2", filter_str)