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

fix: Change how we index the filter operations before evaluation #124

Merged
merged 3 commits into from
Jan 30, 2024

Conversation

SamMayWork
Copy link
Contributor

@SamMayWork SamMayWork commented Jan 29, 2024

Crashes have been observed when using query filters that have a single eq operator in them, this changes the logic so that we actually index the array correctly for these kinds of filters.

(Also adds tests for other short-name operations to prove that those work as intended too.)

Signed-off-by: SamMayWork <sam.may@kaleido.io>
Copy link
Contributor

@EnriqueL8 EnriqueL8 left a comment

Choose a reason for hiding this comment

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

Great find - This function is quiet messy, personally I would refactor it do perform appends. append(array1, array2...) I know probably copy is faster but we are dealing with indexes it can be confusing. There might be a reason with want to do shallow copy as we are modifying it in the for loop for negs?

if len(long) == 0 {
copy(res[0:], short)
} else {
copy(res[len(short):], short)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be len(long) or len(res)? Since we want to copy into from index of where long left off to short...

Suggested change
copy(res[len(short):], short)
copy(res[len(res):], short)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This absolutely should be either long or res here (my bad) and the UT should have caught it but didn't, so will change that too.

This comment indicates some potentially nasty behaviour with append and the existing specific structure here makes me worry for unintended consequences🔥

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in d549fec, looking further at the code short as the index value is obviously wrong, but would actually never cause an issue since if you provide more than one eq value in a block, the other values are ignored. (This means the failure can't be recreated in a UT, since it's not actually a possible condition).

Copy link
Contributor

@EnriqueL8 EnriqueL8 Jan 29, 2024

Choose a reason for hiding this comment

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

Nice post linked, makes sense

Signed-off-by: SamMayWork <sam.may@kaleido.io>
@@ -210,7 +210,13 @@ func (jq *QueryJSON) addSimpleFilters(ctx context.Context, fb FilterBuilder, jso
func joinShortNames(long, short, negated []*FilterJSONKeyValue) []*FilterJSONKeyValue {
res := make([]*FilterJSONKeyValue, len(long)+len(short)+len(negated))
copy(res, long)
copy(res[len(short):], short)
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
copy(res[len(short):], short)
copy(res[len(long):], short)

Isn't this the bug @SamMayWork ?

Copy link
Contributor

Choose a reason for hiding this comment

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

(if there were a problem with copy having nil as the right parameter, then that would be a problem in the line above, which this PR doesn't change)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep after making the change from short -> long the surrounding if block is actually redundant now, removing now 🖊️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 066994c

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (badf065) 99.98% compared to head (d549fec) 99.98%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #124   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files          78       78           
  Lines        6435     6438    +3     
=======================================
+ Hits         6434     6437    +3     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: SamMayWork <sam.may@kaleido.io>
@peterbroadhurst peterbroadhurst merged commit bf98075 into hyperledger:main Jan 30, 2024
2 checks passed
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.

4 participants