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

[Community Contribution] UpdateObject #9119

Conversation

xsoar-bot
Copy link
Contributor

Status

  • In Progress
  • Ready
  • In Hold - (Reason for hold)

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.

Copy link
Contributor

@guyfreund guyfreund left a 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?

Packs/UpdateObject/pack_metadata.json Outdated Show resolved Hide resolved
values = values.split(',')

if index != -1:
original_object[index][key_to_update] = values[0]
Copy link
Contributor

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.

Copy link

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

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link

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

@guyfreund
Copy link
Contributor

guyfreund commented Oct 1, 2020

@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
@ShahafBenYakir
Copy link
Contributor

ShahafBenYakir commented Oct 5, 2020

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.

@LPettay
Copy link

LPettay commented Oct 5, 2020

@ShahafBenYakir @guyfreund I've submitted a pull request here, I'm unable to merge. xsoar-contrib#2

if not isinstance(values, list):
values = values.split(',')

if isinstance(original_object, dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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]
Copy link
Contributor

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

@guyfreund
Copy link
Contributor

guyfreund commented Oct 15, 2020

@LPettay are you intending to submit the changes?

@LPettay
Copy link

LPettay commented Oct 15, 2020

@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.

@guyfreund
Copy link
Contributor

@LPettay so we are closing this in the meantime. When you are back in submitting the changes please re-open the PR.

@guyfreund guyfreund closed this Oct 21, 2020
@xsoar-bot xsoar-bot deleted the LPettay-contrib-UpdateObject branch November 23, 2023 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contribution Thank you! Contributions are always welcome! docs-approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants