Skip to content

fix(memory): pass the configured MySQL charset to the driver - #1221

Open
fxia0018 wants to merge 1 commit into
volcengine:mainfrom
fxia0018:fix/mysql-stm-charset
Open

fxia0018 wants to merge 1 commit into
volcengine:mainfrom
fxia0018:fix/mysql-stm-charset

Conversation

@fxia0018

Copy link
Copy Markdown

Summary

MysqlConfig.charset is documented as a setting: DATABASE_MYSQL_CHARSET, the --short-term-memory-charset flag of veadk harness, and the charset row in the MySQL short-term memory docs. But MysqlSTMBackend never used it. It built the URL as

mysql+pymysql://user:pass@host/db

with no charset, so whatever you set was silently ignored and PyMySQL/aiomysql used their own default.

This PR appends ?charset=<value> to both the pymysql and aiomysql URLs. SQLAlchemy passes it to the driver as the charset connect argument.

Compatibility

  • The documented default was utf8. Both drivers actually use utf8mb4 when no charset is passed (PyMySQL 1.4.6 DEFAULT_CHARSET, aiomysql 0.3.2 charset="utf8mb4"). If the backend started sending utf8 (utf8mb3), existing deployments would lose emoji / 4-byte characters in session data. So the default changes to utf8mb4. For anyone who never set the option, the effective charset is the same as before.
  • Anyone who explicitly set DATABASE_MYSQL_CHARSET / charset now gets that value. That is the documented behavior.
  • charset="" leaves the choice to the driver (no query parameter).
  • Updated the default in the zh/en MySQL docs, the zh/en environment variable reference, config.yaml.full and the veadk harness sample config.

No public Python import or signature changes.

Verification

  • New tests/memory/test_mysql_charset.py:
    • checks that the default, an explicit value and DATABASE_MYSQL_CHARSET all end up in the URL query, for both sync and async drivers;
    • checks that an empty value adds no query;
    • checks that host:port, credentials with special characters and the database are unchanged.
    • Without the fix, 5 of the 7 cases fail.
  • pytest -n 8 -m "not codex_smoke" tests/memory tests/cli: 1904 passed. The one failure, test_build_offline_runtime_creates_local_only_contract, also fails on main locally because node is not installed here.
  • pre-commit run on the changed files: ruff check / ruff format / secret checks pass.

MysqlConfig.charset (DATABASE_MYSQL_CHARSET, --short-term-memory-charset)
was documented but never used: MysqlSTMBackend built the database URL
without it, so the driver always fell back to its own default.

Append ?charset= to both the pymysql and aiomysql URLs. Change the
default from utf8 to utf8mb4, which is what both drivers already used
when no charset was passed, so deployments that never set it keep the
same behavior. An empty value still leaves the choice to the driver.
Update the docs and sample configs to match.

This branch has not been deployed

No deployments
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.

1 participant