Skip to content

[8.0] Replace escape_string with alternatives#8648

Draft
sfayer wants to merge 1 commit into
DIRACGrid:rel-v8r0from
sfayer:sql_escstr_v8
Draft

[8.0] Replace escape_string with alternatives#8648
sfayer wants to merge 1 commit into
DIRACGrid:rel-v8r0from
sfayer:sql_escstr_v8

Conversation

@sfayer

@sfayer sfayer commented Jun 29, 2026

Copy link
Copy Markdown
Member

Backport of #8645.

BEGINRELEASENOTES
*Core
FIX: Replace escape_string with alternatives
ENDRELEASENOTES

@sfayer sfayer marked this pull request as draft June 29, 2026 18:56
@fstagni

fstagni commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Integration tests (server) are failing with:

    @pytest.mark.parametrize("input_val, expected_inner", _ESCAPE_CASES)
    def test_escape_string_escapes_special_chars(input_val, expected_inner):
        """Test that _escapeString properly escapes special characters using a real connection."""
        mysqlDB = setupDB()
        result = mysqlDB._escapeString(input_val)
        assert result["OK"], f"escape_string failed for {input_val!r}: {result.get('Message', '')}"
    
        escaped = result["Value"]
        # If expected_inner is None, default to the input value (no escaping expected)
        expected_inner = expected_inner if expected_inner is not None else input_val
        _expect_quoted(expected_inner, escaped)
    
        # The escaped value should be safe for SQL — verify by inserting it
        result = mysqlDB._createTables(escape_table, force=True)
        assert result["OK"], result["Message"]
    
        # Insert via direct query using the escaped value
        safe_query = f"INSERT INTO EscapeTestTable (Payload) VALUES ({escaped})"
        result = mysqlDB._update(safe_query)
>       assert result["OK"], f"Insert failed with escaped value {escaped!r}: {result.get('Message', '')}"
E       AssertionError: Insert failed with escaped value "'日本語'": MySQL Error ( 1131 : Execution failed.: ( 1366: Incorrect string value: '\xE6\x97\xA5\xE6\x9C\xAC...' for column 'Payload' at row 1 ))
E       assert False

LocalRepo/TestCode/DIRAC/tests/Integration/Core/Test_MySQLDB.py:362: AssertionError
----------------------------- Captured stdout call -----------------------------
2026-06-29 18:44:18,301 UTC Framework/MySQL DEBUG: _query: SHOW TABLES
2026-06-29 18:44:18,302 UTC Framework/MySQL DEBUG: _update: DROP TABLE `EscapeTestTable`
2026-06-29 18:44:18,311 UTC Framework/MySQL DEBUG: _update: INSERT INTO EscapeTestTable (Payload) VALUES ('日本語')
2026-06-29 18:44:18,311 UTC Framework/MySQL ERROR: _update (INSERT INTO EscapeTestTable (Payload) VALUES ('日本語')): Execution failed. 1366: Incorrect string value: '\xE6\x97\xA5\xE6\x9C\xAC...' for column 'Payload' at row 1
------------------------------ Captured log call -------------------------------
DEBUG    dirac.MySQL:(unknown file):0 _query: SHOW TABLES
DEBUG    dirac.MySQL:(unknown file):0 _update: DROP TABLE `EscapeTestTable`
DEBUG    dirac.MySQL:(unknown file):0 _update: INSERT INTO EscapeTestTable (Payload) VALUES ('日本語')
ERROR    dirac.MySQL:(unknown file):0 _update (INSERT INTO EscapeTestTable (Payload) VALUES ('日本語')): Execution failed.
=============================== warnings summary ===============================

which seems to be directly related to your changes. Such failure is only in this branch, not in the rel-v9r0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants