-
-
Notifications
You must be signed in to change notification settings - Fork 764
#4804 Handle action parameters of type array correctly #4861
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
#4804 Handle action parameters of type array correctly #4861
Conversation
…ith the documentation - handle the parameter and transform the array to a string of comma-separated values
I will take a look at the failed test. I was actually reviewing the current tests already and was wondering why that tests did not fail in the past. So, let's see... Investigation ongoing. |
…winem/st2 into fix/4804-serialize-array-in-parameters
So the failed test was caused by:
So, since I don't believe in coincidence this seems to confirm the concerns I mentioned in the PR: just checking the type for I pushed a commit that checks if the type is in |
I reran the failing Travis test and it passed. Solving the intermittent failures on Travis is out of the scope of this PR. At this point the only failing Travis build is the linting run, so fixing that as I've suggested should solve it. @winem If you're still interested in merging this, just make that fix and I'll approve it and merge it in! 😃 |
Hi @blag, do you have any opinion on the |
I reran all of the failing tests - everything passes now! At this point I think we'll need to support both However, this PR also needs at least a unit test for this function so nobody breaks it in the future. You should be able to extend the test for |
Thanks for re-running the tests and and the feedback! I just added the tests. Let's just wait for the unit tests to be done. |
Sorry I should have mentioned this before: please add a changelog entry for this fix. |
No worries, @blag. Could have though of it as well. Anyway, done. 👍 |
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.
👍
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.
I don't see any unit tests that show the difference made by the fix. Looking at just the changes to existing unit tests, I only see that it performs the same function when elif argument_type == 'list':
. Please clarify or add appropriate unit test that show what this PR fixes.
Hi @m4dcoder, I'm sorry but to be honest, I can't follow. So I will just provide as much details as possible and hope that it helps. Without the change from this PR an array would be passed to the shell command as a unicode string if the parameter type is array (as the documentation recommends).
instead of the expected What this PR does is to handle parameters of both types, list and array, the same way and pass the list values as comma separated argument to the shell command runner. I added unit tests which use the So I think I can just come up with tests that prove that the solution works but I can't provide one that reproduces the old behavior and would fail expectedly. Please let me know if I miss anything or got something wrong. |
This is primarily an issue with documented vs actual functionality. Part 1 of the PR: adding
Which references the JSON Schema Spec 4. This section is particularly relevant:
So, Part 2 of the PR: the serialization of arrays/lists
This part of the PR is the part that I think could probably still use another test: st2/st2common/st2common/util/action_db.py Line 288 in 0725178
That is the implementation of @winem's second point:
Maybe this needs one or more tests that demonstrate a list that includes something that is neither int nor string to show when the casting to string is necessary. |
…winem/st2 into fix/4804-serialize-array-in-parameters
…rray and list tests
Hi @cognifloyd, thank you for the extensive answer. Now I got it and totally agree that this kind of test is missing. I added a test for arrays with values of different types and might have found another issue. But this may also be a matter of expectation. So when someone enters a complex number as value it will be interpreted as complex number first and st2 would just pass the result. This is probably obvious for developers but may cause issues in the rare case that a user wants to pass a complex number as parameter to a script. Do we wanna add this to the documentation? |
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.
LGTM
Co-Authored-By: Jacob Floyd <cognifloyd@gmail.com>
@cognifloyd Thanks for the review and feedback, that was helpful! 👍 @m4dcoder this PR is up to you for the final decision/review. |
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.
LGTM
This closes #4804 and actually affects more than just remote shell runner actions.
In the beginning this looked like a simple issue with the serialization and parsing of the parameter but it actually looks like this did not work at all.
So I address 2 issues with this PR:
elif argument_type == 'list':
actually did not match when the type wasarray
. This means that the final else matched and the parameter was just transformed to a unicode string. Although according to the documentation,array
is the correct value (See https://docs.stackstorm.com/actions.html#action-metadata) I see some potential how this could break something in existing environments where the unicode string is already handled by the script and users did not notice that this is actually a bug.Question 1: Do we want to address this and if yes, how? This change should at least be mentioned in the changelog once it's released.
Question 2: Is there any reason (i.e. backward compatibility) I am not aware of to check if the parameter type is either
list
orarray
and not justarray
?join
on an array with strings and integers or other values for example would fail terribly.The solution provided with this PR is the pragmatic approach. It's actually a trade-off and may apply unnecessary casting operations when applying str() to the item.
Alternative approach
The alternative would look like this:
Here we check the type of all the items in an array first and just join the items if they are either just strings or just integers. In all other cases, str() would be applied to all the items in the array.
But I think this just shifts the overhead to another place and is not worth it. I did not do any performance tests with real large arrays yet but I doubt that this matters here. Any input by more experienced experts is appreciated!