tortoise / tortoise/tortoise-orm

Unable to set empty sql_mode for MySQL

Open
#1,311 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Describe the bug
Empty connection url parameters are ignored by Tortoise.init.

To Reproduce

  1. Set connection url to something like mysql://myuser:mypass@db.host:3306/somedb?sql_mode= (empty value for sql_mode).
  2. Call Tortoise.init(...) with debug logs enabled.
  3. Get log message Created connection pool with params: {'host': 'db.host', 'port': 3306, 'user': 'myuser', 'db': 'somedb', 'autocommit': True, 'charset': 'utf8mb4', 'minsize': 1, 'maxsize': 5, 'sql_mode': 'STRICT_TRANS_TABLES'}

Expected behavior
Created connection pool with params: {'host': 'db.host', 'port': 3306, 'user': 'myuser', 'db': 'somedb', 'autocommit': True, 'charset': 'utf8mb4', 'minsize': 1, 'maxsize': 5, 'sql_mode': ''} (empty string as sql_mode).

Additional context
It seems like the problem is caused by parse_qs in expand_db_url, which sets keep_blank_values=False by default. Here https://github.com/tortoise/tortoise-orm/blob/develop/tortoise/backends/base/config_generator.py#L148.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at tortoise/backends/base/config_generator.py around expand_db_url and inspect how the connection URL query is parsed before Tortoise.init creates the MySQL pool. Reproduce the URL with an empty sql_mode and verify that the resulting connection parameters preserve the empty value rather than the default; add or update regression coverage if the existing tests cover URL expansion.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, python
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.