Skip to content

Escape underscores and percent signs in filter matches in Vai #94

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

Merged

Conversation

maxsokolovsky
Copy link
Contributor

@maxsokolovsky maxsokolovsky commented Aug 14, 2024

Issue: rancher/rancher#46410

This PR changes the logic of how ListOptionIndexer builds a SQL query from filters.

The indexer will now escape two characters: _ and %. As a result, the SQL engine will interpret them literally within a LIKE statement, not as special characters as it normally does. For example, it treats _ as a placeholder for a single character. We don't want that. We want it to escape it and look for the literal underscore in a match.

I adjusted existing unit tests but haven't added any new cases, because the current test infrastructure relies on mocked values too much, so I can't assert on returned values from SQL, since those are always mocked.

Added a couple of cases to our new integration tests.

@maxsokolovsky maxsokolovsky requested a review from moio August 14, 2024 17:04
@maxsokolovsky maxsokolovsky requested a review from a team as a code owner August 14, 2024 17:04
@bigkevmcd
Copy link
Contributor

We should have integration tests for this code?

@maxsokolovsky
Copy link
Contributor Author

@bigkevmcd, definitely. It's just that this effort may be outside the scope of this issue. @moio, what do you think?

@bigkevmcd
Copy link
Contributor

@maxsokolovsky I get that, and maybe in this case, yes, but I don't see much value in the mocked version, it's really just testing the mocks?

@tomleb
Copy link
Contributor

tomleb commented Aug 16, 2024

I'm not a fan of those mock tests and we've had discussion about them during the first iteration. We've added a bullet point (used to be in the first iteration GH issue, has been moved to here) about adding integration tests. Also iirc in the very first iteration that @moio worked on, they were reusing tests from upstream's client-go, which I think is a great idea and we should bring that back (also noted in the link).

It seems like even though we have that as a todo, I doubt they'll end up being a priority so maybe we should start adding pieces of non-mock tests as we work through the rest of the tasks. Would it require a lot of effort to add a couple of tests that doesn't just check the query string, but actually runs it with an in-memory sqlite database? @maxsokolovsky

@MbolotSuse
Copy link
Contributor

MbolotSuse commented Aug 16, 2024

@tomleb / @bigkevmcd we have an open issue to backfill tests for lasso: rancher/rancher#45243. If you want to add a comment to that issue requesting that this be part of the backfill, that would be great. However, I'm not in favor of asking @maxsokolovsky to design/implement a way to do this in order for him to submit this small PR.

moio
moio previously approved these changes Aug 20, 2024
@moio
Copy link
Contributor

moio commented Aug 20, 2024

I agree with @MbolotSuse, this is an important topic but should not be tackled in the context of this PR.

@tomleb we have control over importance - there is consensus we deem it important, therefore we will make it happen at the expense of something else.

I approved this PR, and plan to merge it as soon as anybody else adds another approval.

@moio
Copy link
Contributor

moio commented Aug 27, 2024

@tomleb can you please take a look and approve?

@maxsokolovsky
Copy link
Contributor Author

@moio, there is a PR that adds integration tests. If you want, we can wait until that one is merged, and I will add test cases in this PR.

@moio
Copy link
Contributor

moio commented Sep 10, 2024

@maxsokolovsky I like that plan

@maxsokolovsky maxsokolovsky force-pushed the allow-special-characters-as-filters-in-vai branch from 07069e9 to e42a9a5 Compare September 10, 2024 17:28
@maxsokolovsky maxsokolovsky requested a review from moio September 10, 2024 17:30
@maxsokolovsky
Copy link
Contributor Author

Added a couple of cases to our new integration tests.

@maxsokolovsky maxsokolovsky force-pushed the allow-special-characters-as-filters-in-vai branch from e42a9a5 to 24a44ee Compare September 10, 2024 19:44
moio
moio previously approved these changes Sep 11, 2024
Copy link
Contributor

@moio moio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for this contribution

@maxsokolovsky maxsokolovsky force-pushed the allow-special-characters-as-filters-in-vai branch from 24a44ee to ceef6a7 Compare September 12, 2024 13:56
@maxsokolovsky maxsokolovsky requested a review from moio September 12, 2024 13:56
@moio
Copy link
Contributor

moio commented Sep 13, 2024

Nice job, thanks for all the collaboration!

@moio moio merged commit 0106849 into rancher:master Sep 18, 2024
1 check 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.

None yet

5 participants