Skip to content

Escape underscore in archive name when used in like query #21495

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
merged 2 commits into from
Nov 8, 2023
Merged

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Nov 7, 2023

Description:

The ArchiveSelector is responsible for selecting related archives based on the record name. It should select the archive itself, but also all chunks and subtables.

The generated where statement might currently look like this:

WHERE (
  name = 'CustomReports_customreport_1_0' OR 
  (
       name LIKE 'CustomReports_customreport_1_0%' AND
       ( 
	     SUBSTRING(name, 31, 7) = '_chunk_' OR
             ( SUBSTRING(name, 32, 1) >= '0' AND SUBSTRING(name, 32, 1) <= '9') 
        ) 
    )
)

Problem with this query currently is, that the record name in the like query contains (unescaped) underscores (_). MySQL interprets them as a single char wildcard and the records such might also match e.g. CustomReports_customreport_100_0

This one maybe should be backported to 4.x-dev

fixes L3-590

Review

@sgiehl sgiehl added Needs Review PRs that need a code review Regression Indicates a feature used to work in a certain way but it no longer does even though it should. labels Nov 7, 2023
@sgiehl sgiehl added this to the 5.0.0 milestone Nov 7, 2023
@sgiehl sgiehl requested a review from a team November 7, 2023 11:51
Copy link
Member

@mneudert mneudert left a comment

Choose a reason for hiding this comment

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

LGTM, can confirm this solves the issue with the custom report archiving log entries.

@michalkleiner
Copy link
Contributor

Is there a test we can adjust or add to make sure this doesn't regress in future?

Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

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

The change (either the original one or the suggested one) solves the issue, so approving. It'd be nice if there was a test covering this.

Co-authored-by: Michal Kleiner <michal@innocraft.com>
@sgiehl
Copy link
Member Author

sgiehl commented Nov 8, 2023

@michalkleiner There are currently no tests that are covering that part of the code directly, so there isn't anything that could be extended easily. Also the problem is, that core doesn't contain any record names that end with a dynamic number. That is only the case for custom reports plugin. Tests in custom reports plugin actually kind of covered this, but as it "only" causes an info message being logged and no further problems that wasn't caught earlier.
Anyway, I agree that the whole archiving stuff would need a lot more unit testing to ensure every single part works as expected. But starting this as part of this PR might be a bit too time consuming, considering this is only a quick fix, that already consumed more time that it should have...

@sgiehl sgiehl merged commit 59098a7 into 5.x-dev Nov 8, 2023
@sgiehl sgiehl deleted the l3-590 branch November 8, 2023 10:47
sgiehl added a commit that referenced this pull request Nov 8, 2023
* Escape underscore in archive name when used in like query

* apply review feedback

Co-authored-by: Michal Kleiner <michal@innocraft.com>

---------

Co-authored-by: Michal Kleiner <michal@innocraft.com>
sgiehl added a commit that referenced this pull request Nov 8, 2023
…21504)

* Escape underscore in archive name when used in like query

* apply review feedback



---------

Co-authored-by: Michal Kleiner <michal@innocraft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Development

Successfully merging this pull request may close these issues.

3 participants