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

ResultPath=$ replaces complete output #199

Merged
merged 1 commit into from
Jun 3, 2024
Merged

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented May 31, 2024

ok, https://states-language.net/#error-output

The default value, if the "ResultPath" field is not provided, is "$", meaning that the output consists entirely of the Error Output.

Which differs from the previous code
https://github.com/ManageIQ/floe/blob/master/lib/floe/workflow/reference_path.rb#L28-L29

If the payload is '$' then merge the value into the context

This fixes issues where the output is a simple class inserting at the top level

I stumbled across this because the Task Catch should output the error as the output node

@kbrock kbrock added the bug Something isn't working label May 31, 2024
@kbrock kbrock requested review from agrare and Fryguy as code owners May 31, 2024 03:50
@kbrock
Copy link
Member Author

kbrock commented May 31, 2024

update:

  • ugh. fixed last minute optimization (that flubbed things up)

return value.dup if path.empty?

child = result = context.dup
path[..-2].each do |key|
Copy link
Member

Choose a reason for hiding this comment

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

path[..-2] is melting my brain...is it chomping off the last character? If so, is it chomping off a specific character (asking cause then you can use the chomp method with a parameter.

Copy link
Member Author

Choose a reason for hiding this comment

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

yea. I wanted to get rid of the dup, but maybe this is the same.

This is

- keys     = path.dup
- last_key = keys.pop
- keys.each do |key|
+ path[..-2].each do
  ...
  end
- child[last_key]
+ child[path.last]

probably same as:

- keys     = path.dup
- last_key = keys.pop
+ *keys, last_key = path

Though all of these may allocate the same so this may be an unnecessary change.

Copy link
Member

Choose a reason for hiding this comment

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

@kbrock can we tackle this in a different refactoring PR if https://github.com/ManageIQ/floe/pull/199/files#r1622463119 is the primary fix here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if it is any better.
Will probably forget all about this change. (as it should be)

Good call getting in the important stuff and changing as little as possible

Comment on lines 32 to 33
if path.empty?
result.merge!(value)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main change

  if path.empty?
-   result.merge!(value)
+   value.dup

let(:input) { {} }
let(:input) { { "old" => "key"} }
Copy link
Member Author

Choose a reason for hiding this comment

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

this was an empty hash before, so the tests did not show the distinction here.
Adding a before value caused the code to show the nuance I am highlighting

@agrare
Copy link
Member

agrare commented May 31, 2024

Great catch @kbrock

@@ -50,19 +50,27 @@

describe "#set" do
let(:payload) { "$" }
let(:input) { {} }
let(:input) { { "old" => "key"} }
Copy link
Member

Choose a reason for hiding this comment

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

Rubocop has a good point

Suggested change
let(:input) { { "old" => "key"} }
let(:input) { {"old" => "key"} }

@kbrock kbrock force-pushed the empty_path branch 2 times, most recently from 4732951 to b20a993 Compare May 31, 2024 20:55
@kbrock
Copy link
Member Author

kbrock commented May 31, 2024

update:

  • rebase
  • rolled back code changes and kept value replace

update:

  • fixed cop with spacing

@kbrock kbrock mentioned this pull request Jun 1, 2024
2 tasks
ok, https://states-language.net/#error-output

> The default value, if the "ResultPath" field is not provided, is "$", meaning that the output consists entirely of the Error Output.

Which differs from the previous code
 https://github.com/ManageIQ/floe/blob/master/lib/floe/workflow/reference_path.rb#L28-L29

> If the payload is '$' then merge the value into the context

This fixes issues where the output is a simple class inserting at the top level
@miq-bot
Copy link
Member

miq-bot commented Jun 3, 2024

Checked commit kbrock@c3ba972 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
3 files checked, 0 offenses detected
Everything looks fine. 🍰

@agrare agrare merged commit 41384a6 into ManageIQ:master Jun 3, 2024
5 checks passed
@kbrock kbrock deleted the empty_path branch June 3, 2024 14:52
@agrare agrare self-assigned this Jun 3, 2024
agrare added a commit that referenced this pull request Jun 20, 2024
Fixed
- ResultPath=$ replaces complete output (#199)
- Fix retrier backoff values (#200)
- Fix Retry issues (#202)
- Add Apache-2.0 license (#217)

Changed
- Update gemspec summary (#205)
- Simpler State#long_name (#204)
- State only modifies Context#state - prep for Map/Parallel (#206)
- Set StateHistory in Workflow not State (#211)
- Make Runner#wait optional (#190)
- Pass credentials around with context (#203)
- Pass context to State without workflow (#216)
- Move the guts of the CLI into a class for easy testing (#220)

Added
- Set State PreviousStateGuid in StateHistory (#208)
- Add a codeclimate config file (#224)
- Add an Execution unique ID to Context (#226)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants