fix query ids with % char#117
Conversation
📝 WalkthroughWalkthroughThis PR parameterizes ID values in SQL WHERE clauses, adds a percent-escaping utility for SQL strings, lowers some log levels to debug, and adds integration tests for special-character handling in IDs, documents, and metadata. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant BaseClient
participant SQLUtils
participant DB
Client->>BaseClient: collection.get(ids / filters)
BaseClient->>SQLUtils: escape_percent_for_sql(id) (if needed)
BaseClient->>BaseClient: _convert_id_to_sql_with_paramters(id) -> (sql_fragment, param)
BaseClient->>DB: execute SQL with parameterized ID and params
DB-->>BaseClient: query result
BaseClient-->>Client: return documents/metadatas
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/pyseekdb/client/client_base.py`:
- Around line 1794-1799: The loop currently calls
_convert_id_to_sql_with_paramters(id_val) which pre-escapes the ID and returns
an escaped parameter that then gets passed into cursor.execute, causing
double-escaping; change the behavior so the raw ID value is passed as the
parameter instead of an escaped string—either update
_convert_id_to_sql_with_paramters to return an unescaped parameter (raw id_val)
and an SQL placeholder (e.g., "%s"), or stop using its escaped output and pass
the original id_val as the param when appending to params; ensure processed_ids
still contains the SQL fragment/placeholder while params contains the raw id
value so PyMySQL can perform the proper escaping during cursor.execute.
🧹 Nitpick comments (1)
tests/integration_tests/test_special_characters_bugs.py (1)
18-20: Consider adding explicit collection cleanup.Each test creates a new collection; adding a
try/finallyteardown (or a small helper) to drop it would keep the test DB clean and reduce long‑run flakiness.
Summary
close #116
If there's '%' in the
idfield, thecollection.getwould failed to execute.I use parameterized query with pymysql, so we should treat the
idparameter as a parameter incursor.execute. But it's serialized in SQL now.Currently:
After I fix the bug:
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.