fix(api): restore CJK keyword search in workflow logs broken by PR #30450#37542
Open
ifer47 wants to merge 1 commit into
Open
fix(api): restore CJK keyword search in workflow logs broken by PR #30450#37542ifer47 wants to merge 1 commit into
ifer47 wants to merge 1 commit into
Conversation
…nggenius#30450 PR langgenius#30450 replaced the unicode_escape encoding with escape_like_pattern() for SQL injection safety, but this broke CJK keyword searches because json.dumps() defaults to ensure_ascii=True, storing CJK characters as \uXXXX escape sequences in the database. Searching for raw CJK characters no longer matches the stored \uXXXX form. This fix adds a dual-search strategy: when the keyword contains non-ASCII characters, both the raw-CJK form and the unicode-escaped form are used as LIKE patterns (OR'd together). This ensures matches regardless of whether the data was stored with ensure_ascii=True (default repository) or ensure_ascii=False (logstore backend). Pure ASCII keywords skip the extra search to avoid unnecessary overhead. Closes langgenius#37367 Co-Authored-By: zhipu/glm-5 <zai-org@claude-code-best.win>
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.
Summary
unicode_escapeencoding withescape_like_pattern()for SQL injection safety, but broke CJK search becausejson.dumps()defaults toensure_ascii=True, storing CJK characters as\uXXXXescape sequences in the databaseRoot Cause
Before PR #30450, the code used:
This converted CJK keywords to
\uXXXXformat, matching howjson.dumps(ensure_ascii=True)stores data in PostgreSQL. PR #30450 replaced this withescape_like_pattern()which only escapes SQL LIKE wildcards (%,_,\), so searching for raw你好cannot match\u4f60\u597dstored in the database.Fix
When the keyword contains non-ASCII characters:
ILIKE '%你好%' ESCAPE '\'— matches data stored withensure_ascii=False(e.g., logstore backend)ILIKE '%\u4f60\u597d%' ESCAPE '\'— matches data stored withensure_ascii=True(default)Pure ASCII keywords skip the extra search to avoid unnecessary overhead.
Test plan
test_workflow_app_log_cjk_search.pycovering CJK, mixed ASCII+CJK, pure ASCII, and LIKE special character edge casesCloses #37367
🤖 Generated with Claude Code Best