ibmresilient / resilient-community-apps

Source code for IBM SOAR Apps that are available on our App Exchange
https://ibm.biz/soar-apps-docs
MIT License
88 stars 96 forks source link

Data Table Utils: Get Row fails when the column I'm searching for is empty #59

Open LiamMahoney opened 3 years ago

LiamMahoney commented 3 years ago

Description

The function Data Table Utils: Get Row fails when one of the cells that is searched before the value is empty. This is because bracket notation is being used to access the value of the cell. If the cell does not have a value (it's empty) then the value key doesn't exist in the cell dictionary and the code raises a KeyError exception.

Describe How to Reproduce

If I have the following data table:

data-table-example

and I am using the Data Table Utils: Get Row function to search for a row that has a value of 'testing' in the 'Username' column, the function will throw a KeyError with the following stack trace:

Traceback (most recent call last):
  File "/home/liam/Documents/resilient/resilient-community-apps/fn_datatable_utils/fn_datatable_utils/components/dt_utils_get_row.py", line 72, in _dt_utils_get_row_function
    row = datatable.get_row(payload.inputs["dt_utils_row_id"], payload.inputs["dt_utils_search_column"], payload.inputs["dt_utils_search_value"])
  File "/home/liam/Documents/resilient/resilient-community-apps/fn_datatable_utils/fn_datatable_utils/util/helper.py", line 42, in get_row
    if cells[search_column]["value"] == search_value:
KeyError: 'value'

This happens because line 42 in fn_datatable_utils/fn_datatable_utils/util/helper.py uses bracket notation if cells[search_column]["value"] == search_value:. The row object looks like this:

row = {
  "id": 41623,
  "cells": {
    "service_account_username": {
      "id": "service_account_username",
      "row_id": 41623
    },
    "service_account_ad_description": {
      "id": "service_account_ad_description",
      "row_id": 41623
    }
  },
  "actions": [],
  "type_id": 1101,
  "table_name": "Service Account(s) Invovled",
  "inc_id": 3450,
  "inc_name": "Data Table Test",
  "inc_owner": "Testing Group",
  "version": 0
}

and cells[search_column] looks like this:

cells[search_column] = {
    "service_account_username": {
     "id": "service_account_username",
     "row_id": 41623
}

Since cells[search_column] does not have a key 'value' the KeyError is thrown.