Repository navigation
fix(cypher): report an =~ pattern that does not compile - #3069
Open
Zhuoxi2000 wants to merge 2 commits into
Open
Zhuoxi2000 wants to merge 2 commits into
Zhuoxi2000 wants to merge 2 commits into
Conversation
…ning Regression test for DeusData#3022. On main the compile failure of an =~ pattern is swallowed per row: the query answers rc 0 with no rows, no error and no warning, and under NOT it answers every row. Only the compile-size refusal (CBM_REG_ETOOBIG) is surfaced today. The test pins the engine contract for a pattern no dialect accepts (an unbalanced group): rc 0, the comparison false on every row, and a warning that names the pattern. For the reporter's `(?i)` pattern it accepts either that warning or, on a regex backend that implements the flag (the TRE build used on Windows parses `(?...)`), the three case-insensitive matches. When the pattern is read from the row (`a.name =~ b.name`) the test pins a warning that repeats no property value and does not say "every row": the row whose value does compile is still returned. Signed-off-by: Edson <zhuoxi2000@gmail.com>
eval_comparison_op returned false whenever cbm_regcomp failed and only
flagged the compile-size refusal (CBM_REG_ETOOBIG). Any other compile
error, such as an unbalanced group or the `(?i)` flag POSIX ERE does not
have, turned into "row does not match" on every row with nothing in the
result to say so: `WHERE f.name =~ "(?i)claim.*"` answered rc 0 and no
rows, and `WHERE NOT f.name =~ ".*Order("` answered every row.
The first literal pattern the platform compiler rejects during an
execution is now recorded and cbm_cypher_execute names it in
result->warning, next to the existing traversal and too-large warnings.
query_graph already emits that field. The comparison still evaluates to
false and the query still returns rc 0, as it does for an oversized
pattern, so no query that answered before starts failing. The echoed
pattern is capped at 127 bytes, cut on a code point boundary and marked
with "...".
A pattern read from the row (`a.name =~ b.name`) gets a separate
warning that repeats no value: it is graph data, not query text, and
only the rows holding such a value compared false. The warning buffer
grows from 512 to 1024 bytes so that all four notices fit together.
Inline property patterns ({name: "..."}) are unchanged: a value that
does not compile there falls back to a literal comparison.
Fixes DeusData#3022
Signed-off-by: Edson <zhuoxi2000@gmail.com>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #3022
In
query_graph, an=~pattern that the regex compiler rejects is now reported in the result'swarningfield. A pattern written in the query is named; a pattern read from a row is reported without its value. Before, nothing in the result said the pattern had never run:WHERE f.name =~ '(?i)claim.*'answered 0 rows with the generic "no results" hint (the case in query_graph:=~with an unsupported pattern such as(?i)silently returns 0 rows instead of an error #3022).WHERE NOT f.name =~ 'claim('answered every row. query_graph:=~with an unsupported pattern such as(?i)silently returns 0 rows instead of an error #3022 does not mention this form; it is the same swallowed failure seen throughNOT.Cause.
eval_comparison_op(src/cypher/cypher.c) returnsfalsewhenevercbm_regcompfails. Only the compile-size refusal (CBM_REG_ETOOBIG, added in #2475) sets the flag thatcbm_cypher_executeturns intoresult->warning. Every other compile error became "row does not match" on every row.Change (
src/cypher/cypher.c, +68/-5 lines, no other source file):g_cypher_regex_refusedand reset with it.cbm_cypher_executeappends a warning after the existing traversal and too-large warnings:=~ pattern '<pattern>' is not a valid POSIX extended regular expression — the comparison evaluated to false on every row....WHERE a.name =~ b.name(query_graph: a WHERE comparison between two properties (a.file_path = b.file_path) fails with "expected value at pos N" #2591) takes its pattern from the row. That value is graph data, not query text, and only the rows that hold a value that does not compile compare false. This case sets a separate flag and gets its own warning, which repeats no value:=~ pattern read from a property or alias is not a valid POSIX extended regular expression on at least one row — the comparison evaluated to false on those rowseval_comparison_optakes aboolthat says which of its two callers supplied the pattern.cbm_cypher_executegrows from 512 to 1024 bytes. The four notices together are about 670 bytes at worst.src/mcp/mcp.cis not touched:query_graphalready writesresult->warningin both output formats.Why a warning and not an error. #3022 suggests an error, and
search_codereturns one for an invalid pattern since #283 ("conflating "broken pattern" with "no matches" wastes debugging time"). I kept the shape #2475 chose for this same code path: the comparison still evaluates to false, the query still returns rc 0, and the warning carries the reason. The comment oncypher_exec_where_regex_oversized_pattern_matches_nothingalready describes it: the comparison "matches nothing, as for any pattern that cannot be compiled", and "the engine keeps answering". Until now only the oversized case reached the warning. Keeping that shape means no query that answers today starts failing, for exampleWHERE f.name =~ 'bad(' OR f.name = 'x', which still returns thexrows. The cost is that theNOTform still returns every row, now with the warning attached. If you would rather have a query error here, it is a small change on top of this one (the pattern is already recorded) and I am happy to switch.Result, end to end with the built binary on a four-function Python file (
claim_order,claim_refund,Claim_Legacy,log_error):=~ 'claim.*'on the same index returnsclaim_orderandclaim_refundwith no warning.A pattern read from a row, on a second index of three files:
orders.py(the four functions above),claim.py(claim_all) and a file namedclaim(.py(claim_bad). The file nameclaim(.pydoes not compile as a pattern. The functions of the other two files are returned and the warning does not repeat the name:Limits of this change, and what it leaves alone:
=~(no candidate nodes, or anANDthat short-circuits before it) carries no warning.;.{name: "..."}) are unchanged. A value that does not compile there falls back to a literal comparison, which looks deliberate.(?i)support (suggestion 2 in query_graph:=~with an unsupported pattern such as(?i)silently returns 0 rows instead of an error #3022). Stripping a leading(?i)and compiling withCBM_REG_ICASEchanges what existing queries match, so it should be its own change. I can send it as a follow-up if you want it.=~is POSIX ERE would fit next to theWHEREoperator list; I left it out to keep this PR to one claim.Platforms. Only macOS was run locally. An unbalanced group is rejected by every backend, so the assertions that use one (the literal pattern, the
NOTform, the length cap and the pattern read from a row) do not depend on the platform. The(?i)assertion does: libcregcompon macOS rejects it, while the vendored TRE used on Windows has a(?...)branch invendored/tre/tre-parse.cand may accept it. The test therefore accepts either the warning or the three case-insensitive matches for that one pattern. Linux, FreeBSD and Windows are left to CI.Checklist
git commit -s):scripts/check-dco.sh origin/main..HEADreportsOK: 2 commit(s) in origin/main..HEAD carry a valid Signed-off-by.make -f Makefile.cbm testhangs on this machine during ASan shadow-memory init, beforemain()(macOS 26.5, Apple clang 17.0.0), so an unsanitized runner was used:make -f Makefile.cbm -j4 SANITIZE= BUILD_DIR=build/nosan build/nosan/test-runner. The sanitized run is left to CI. Suites run with the fix:cypher: 246 passedmcp: 438 passed, 4 skippedintegration: 27 passedstore_search: 78 passedmake -f Makefile.cbm lint-formatwith clang-format 20.1.8: clean overLINT_SRCSandLINT_HDRS.tests/test_cypher.chas two violations that are already onmain(theASSERT_TRUE(ref_query(call at line 6168 onmain; test files are not inLINT_SRCS) and none in the lines this PR adds.make -f Makefile.cbm lint-cppcheckwith cppcheck 2.20.0 (built from the tag CI uses) passes.lint-no-suppress,lint-memory-core,lint-vendored-scannersandscripts/check-no-test-skips.shpass.lint-ci) was not run.cypher_exec_where_regex_invalid_pattern_is_reported_issue3022intests/test_cypher.c.Test evidence
Machine: Apple M4, macOS 26.5, Apple clang 17.0.0. Base:
mainat 1111d9a.Before (test commit only,
src/cypher/cypher.cas onmain):After (both commits):
The test pins, for the unbalanced pattern
.*Order(: rc 0, 0 rows, and a warning that contains the pattern and the reason. For theNOTform it pins rc 0 and the warning. It checks that a 201-byte pattern is cut on a code point boundary and marked. Fora.name =~ b.nameit builds a three-node store in whichCallercalls one function namedCall.*and one namedUnbalanced(Name, and pins: rc 0, the one row whose pattern compiles is returned, a warning is present, and the warning contains neitherUnbalancednor "every row". Last, a valid pattern run afterwards returns its 3 rows with no warning.Size: 2 commits (test, then fix), 2 files, +182/-5 lines (
src/cypher/cypher.c+68/-5,tests/test_cypher.c+114).AI assistance: this change was drafted with an AI coding assistant (Claude) and verified locally with the tests above.