-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Community Contribution] UpdateObject #9119
[Community Contribution] UpdateObject #9119
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when values and original_object are not of the same length?
values = values.split(',') | ||
|
||
if index != -1: | ||
original_object[index][key_to_update] = values[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if original_object is a dict you'll get a KeyError, please fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in xsoar-contrib#2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, original_dict is a list (when you implement the above suggestion) but one of the items in the list isn't a dict you'll get an error again, please fix it
original_object[index][key_to_update] = values[0] | ||
else: | ||
for idx, (obj, val) in enumerate(zip(original_object, values)): | ||
original_object[idx][key_to_update] = val |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if original_object is a dict you'll get a KeyError, please fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in xsoar-contrib#2
@LPettay please submit the needed changes as we want to proceed on to merging this contribution, thanks! |
- Removed example from pack description + Added handling for when original_object is a dict instead of list
Hi there @LPettay if you are aiming to contribute this pack please address the relevant comments so we can get this pack merged, if not please let us know as soon as possible, as we are allocating resources to handle this contribution process. |
@ShahafBenYakir @guyfreund I've submitted a pull request here, I'm unable to merge. xsoar-contrib#2 |
Implemented suggested fixes
if not isinstance(values, list): | ||
values = values.split(',') | ||
|
||
if isinstance(original_object, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isinstance(original_object, dict): | |
if not isinstance(original_object, list): |
values = values.split(',') | ||
|
||
if index != -1: | ||
original_object[index][key_to_update] = values[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, original_dict is a list (when you implement the above suggestion) but one of the items in the list isn't a dict you'll get an error again, please fix it
@LPettay are you intending to submit the changes? |
@guyfreund I intend to submit them once I have the time, this is low on my priorities at the moment. Dealing with many customer issues this week. |
@LPettay so we are closing this in the meantime. When you are back in submitting the changes please re-open the PR. |
Status
Description
@LPettay's pack description: Updates the values within an array of objects for a given key.
Example Command:
!UpdateObject original_object=${myobject} key_to_update="Key1" values="newval1,newval2,newval3"
Results:
Original Object (myobject):
[
{
'Key1': 'oldval1',
'Key2': 'key2val1'
}, {
'Key1': 'oldval2',
'Key2': 'key2val2'
}, {
'Key1': 'oldval3',
'Key2': 'key2val3'
}
]
Updated Object (mynewobject):
[
{
'Key1': 'newval1',
'Key2': 'key2val1'
}, {
'Key1': 'newval2',
'Key2': 'key2val2'
}, {
'Key1': 'newval3',
'Key2': 'key2val3'
}
]
Video Link
Short demo video of the Pack usage. Speeds up the review. Optional but recommended. Use a video sharing service such as Google Drive or YouTube.