howiezhao commented on PR #1292:
URL: 
https://github.com/apache/cassandra-python-driver/pull/1292#issuecomment-4387923680

   > Would prefer something more concise, maybe something like...
   > 
   > `.. warning::
   > 
   > **Avoid "Round-Tripping" data using string formatting.**
   > 
   > Never use f-strings or `%` to insert data—especially driver-returned 
collections (maps, sets, lists)—back into a CQL query.
   > 
   > **The Gotcha:** The driver's collection objects use Python's `repr()` 
formatting for nested values. This automatically doubles backslashes (e.g., `\` 
becomes `\\`). Because CQL does not use backslashes as escape characters, 
Cassandra will store those extra backslashes literally, **corrupting your 
data.**
   > 
   > **The Fix:** Always use **prepared statements**. They transmit data in a 
binary format that bypasses Python's string serialization entirely.
   > 
   > .. code-block:: python
   > 
   > ```
   > # BAD: f-strings cause double-escaping/corruption
   > session.execute(f"UPDATE t SET my_map={row.my_map} WHERE id=1")
   > 
   > # GOOD: Prepared statements preserve data exactly
   > stmt = session.prepare("UPDATE t SET my_map=? WHERE id=1")
   > session.execute(stmt, [row.my_map])`
   > ```
   
   Hi @bschoening good suggestion, updated


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to