Skip to content

Commit b24508e

Browse files
return results failed to receive a result entry in a list (demisto#12419)
* Fixed a bug where return results failed to receive a demisto results entry * removed unnecessary return and added rn * removed return * fixed return_results * Changed version * Changed version * Changed version * Update 1_10_9.md * Added tests Reverted changes to show test is failing * Reverted changes to show the added test is failing * fix * added fix back * version * Bumped meta version * Removed unnecessary condition * Removed unnecessary condition * Changed versions * Changed versions * Pull from master * Bumped metadata version Co-authored-by: roysagi <[email protected]>
1 parent a0c2d43 commit b24508e

4 files changed

Lines changed: 46 additions & 18 deletions

File tree

Packs/Base/ReleaseNotes/1_10_13.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
#### Scripts
3+
##### CommonServerPython
4+
- Improved implementation of the *return_results* method in order to handle a list of mixed results objects.

Packs/Base/Scripts/CommonServerPython/CommonServerPython.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,36 +5033,38 @@ def return_results(results):
50335033
demisto.results(None)
50345034
return
50355035

5036-
if results and isinstance(results, list) and len(results) > 0 and isinstance(results[0], CommandResults):
5036+
elif results and isinstance(results, list):
5037+
result_list = []
50375038
for result in results:
5038-
demisto.results(result.to_context())
5039-
return
5039+
if isinstance(result, (dict, str)):
5040+
# Results of type dict or str are of the old results format and work with demisto.results()
5041+
result_list.append(result)
5042+
else:
5043+
# The rest are of the new format and have a corresponding function (to_context, to_display, etc...)
5044+
return_results(result)
5045+
if result_list:
5046+
demisto.results(result_list)
50405047

5041-
if isinstance(results, CommandResults):
5048+
elif isinstance(results, CommandResults):
50425049
demisto.results(results.to_context())
5043-
return
50445050

5045-
if isinstance(results, BaseWidget):
5051+
elif isinstance(results, BaseWidget):
50465052
demisto.results(results.to_display())
5047-
return
50485053

5049-
if isinstance(results, GetMappingFieldsResponse):
5054+
elif isinstance(results, GetMappingFieldsResponse):
50505055
demisto.results(results.extract_mapping())
5051-
return
50525056

5053-
if isinstance(results, GetRemoteDataResponse):
5057+
elif isinstance(results, GetRemoteDataResponse):
50545058
demisto.results(results.extract_for_local())
5055-
return
50565059

5057-
if isinstance(results, GetModifiedRemoteDataResponse):
5060+
elif isinstance(results, GetModifiedRemoteDataResponse):
50585061
demisto.results(results.to_entry())
5059-
return
50605062

5061-
if hasattr(results, 'to_entry'):
5063+
elif hasattr(results, 'to_entry'):
50625064
demisto.results(results.to_entry())
5063-
return
50645065

5065-
demisto.results(results)
5066+
else:
5067+
demisto.results(results)
50665068

50675069

50685070
# deprecated

Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3280,11 +3280,33 @@ def test_return_results_multiple_dict_results(mocker):
32803280
demisto_results_mock = mocker.patch.object(demisto, 'results')
32813281
mock_command_results = [{'MockContext': 0}, {'MockContext': 1}]
32823282
return_results(mock_command_results)
3283-
args, kwargs = demisto_results_mock.call_args_list[0]
3283+
args, _ = demisto_results_mock.call_args_list[0]
32843284
assert demisto_results_mock.call_count == 1
32853285
assert [{'MockContext': 0}, {'MockContext': 1}] in args
32863286

32873287

3288+
def test_return_results_mixed_results(mocker):
3289+
"""
3290+
Given:
3291+
- List containing a CommandResult object and two dictionaries (representing a demisto result entries)
3292+
When:
3293+
- Calling return_results()
3294+
Then:
3295+
- Assert that demisto.results() is called 2 times .
3296+
- Assert that the first call was with the CommandResult object.
3297+
- Assert that the second call was with the two demisto results dicts.
3298+
"""
3299+
from CommonServerPython import CommandResults, return_results
3300+
demisto_results_mock = mocker.patch.object(demisto, 'results')
3301+
mock_command_results_object = CommandResults(outputs_prefix='Mock', outputs={'MockContext': 0})
3302+
mock_demisto_results_entry = [{'MockContext': 1}, {'MockContext': 2}]
3303+
return_results([mock_command_results_object] + mock_demisto_results_entry)
3304+
3305+
assert demisto_results_mock.call_count == 2
3306+
assert demisto_results_mock.call_args_list[0][0][0] == mock_command_results_object.to_context()
3307+
assert demisto_results_mock.call_args_list[1][0][0] == mock_demisto_results_entry
3308+
3309+
32883310
def test_arg_to_int__valid_numbers():
32893311
"""
32903312
Given

Packs/Base/pack_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Base",
33
"description": "The base pack for Cortex XSOAR.",
44
"support": "xsoar",
5-
"currentVersion": "1.10.12",
5+
"currentVersion": "1.10.13",
66
"author": "Cortex XSOAR",
77
"serverMinVersion": "6.0.0",
88
"url": "https://www.paloaltonetworks.com/cortex",

0 commit comments

Comments
 (0)