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

add logic to save extractor keys as array if string #1611

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

Tooyosi
Copy link
Contributor

@Tooyosi Tooyosi commented Oct 8, 2024

Solves for this ticket

Copy link
Contributor

@yuenmichelle1 yuenmichelle1 left a comment

Choose a reason for hiding this comment

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

I'm not convinced we need to save extractor keys as an array/convert into a string.

I think we could get away with something like:

begin
  filters['extractor_keys'] = JSON.parse(filters['extractor_keys'])
 rescue JSON::ParserError, TypeError;
 end

But happy to be wrong on this.


def convert_to_array(input)
if input.strip.start_with?("[") && input.strip.end_with?("]")
json_string = input.gsub("'", '"')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could line lead to weird behavior. As an eg. someone enters a single quote within a double quote within an array eg inputting ["'hello'"] . I think as you edit the reducer, this logic starts getting wonky.

Granted a person shouldnt be doing something like that anyway cuz I'm assuming the reducer won't run well 😆 , but technically via caesar ui is still a "valid" input.

@Tooyosi
Copy link
Contributor Author

Tooyosi commented Oct 9, 2024

I'm not convinced we need to save extractor keys as an array/convert into a string.

I think we could get away with something like:

begin
  filters['extractor_keys'] = JSON.parse(filters['extractor_keys'])
 rescue JSON::ParserError, TypeError;
 end

But happy to be wrong on this.

I agree - looking again, the convert_to_array logic is an overkill. The values save as is when the exception is caught so your suggestion would fly. Pushing this update in a bit

@@ -96,6 +96,16 @@
expect(workflow.reducers.first.filters['extractor_keys']).to eq(['test'])
end

it 'saves extractor_keys as an array' do
nested_reducer_params[:extractor_keys] = 'test'
Copy link
Contributor

Choose a reason for hiding this comment

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

Thats weird. I would have expected if we set extractor keys input to a string that it would keep as string. Maybe you mean nested_reducer_params[:filters][:extractor_keys] ?

@yuenmichelle1 yuenmichelle1 self-requested a review October 9, 2024 22:25
Copy link
Contributor

@yuenmichelle1 yuenmichelle1 left a comment

Choose a reason for hiding this comment

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

Hey Toyosi! Some quick changes in the test and then you should be good.

I think your save extractor_keys as an array might not be tested correct behavior. I think you might need to update L100 to
nested_reducer_params[:filters][:extractor_keys] = 'test' .

Maybe nitpicky but I would also test the the case of '"test"'. (This is the case for the current behavior on caesar. Entering "test" on the input field actually sends nested_reducer_params[:filters][:extractor_keys] as '"test"' which is JSON parseable.)

@Tooyosi Tooyosi merged commit 4ff7c17 into master Oct 15, 2024
2 checks passed
@Tooyosi Tooyosi deleted the fix-extractor-parsing branch October 15, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants