fix: reject autocommit=False override and IS NULL condition handling
_where() rendered None conditions as col = %s bound to NULL, which sql never matches, so get/get_one/exists/delete silently missed NULL rows despite insert() writing NULL fine — fixed to emit col IS NULL, in lockstep with the psql lib's identical fix. Separately, __init__ now rejects autocommit=False in pool_kwargs: with it, _run/_fetchall never commit, so on pool release aiomysql closes the in-transaction connection and MySQL rolls back server-side while insert()/delete()/upsert()/execute() still return success signals (lastrowid/rowcount) for writes that were silently discarded. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
@@ -11,18 +11,18 @@ wire-compatible and share the driver, so this covers both.
|
|||||||
`requirements.txt`:
|
`requirements.txt`:
|
||||||
|
|
||||||
```
|
```
|
||||||
mysql @ git+ssh://git@git.rethinkstudios.io/rethink-public/mysql.git@v0.1.2
|
mysql @ git+ssh://git@git.rethinkstudios.io/rethink-public/mysql.git@v0.1.3
|
||||||
```
|
```
|
||||||
|
|
||||||
Direct:
|
Direct:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "mysql @ git+ssh://git@git.rethinkstudios.io/rethink-public/mysql.git@v0.1.2"
|
pip install "mysql @ git+ssh://git@git.rethinkstudios.io/rethink-public/mysql.git@v0.1.3"
|
||||||
```
|
```
|
||||||
|
|
||||||
Pulls `aiomysql` (which pulls `PyMySQL`).
|
Pulls `aiomysql` (which pulls `PyMySQL`).
|
||||||
|
|
||||||
Drop the `@v0.1.2` suffix from the line above to install the latest unpinned.
|
Drop the `@v0.1.3` suffix from the line above to install the latest unpinned.
|
||||||
|
|
||||||
## The two-layer API
|
## The two-layer API
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "mysql"
|
name = "mysql"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
description = "async mysql/mariadb wrapper over aiomysql: two-layer API (friendly verbs + raw escape hatch), fail-loud, config-free"
|
description = "async mysql/mariadb wrapper over aiomysql: two-layer API (friendly verbs + raw escape hatch), fail-loud, config-free"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
+22
-5
@@ -92,9 +92,17 @@ class MysqlDB:
|
|||||||
|
|
||||||
host/port/db/user/password/minsize/maxsize are injected by the caller. extra
|
host/port/db/user/password/minsize/maxsize are injected by the caller. extra
|
||||||
pool_kwargs pass through to aiomysql.create_pool (unix_socket, ssl, charset, ...).
|
pool_kwargs pass through to aiomysql.create_pool (unix_socket, ssl, charset, ...).
|
||||||
rows come back as dicts (DictCursor) and autocommit is on by default; both can be
|
rows come back as dicts (DictCursor), overridable via pool_kwargs. autocommit is
|
||||||
overridden via pool_kwargs.
|
always on: layer-1 verbs and raw execute() rely on it to commit on their own, so
|
||||||
|
`autocommit=False` in pool_kwargs is rejected (use transaction() for atomic
|
||||||
|
multi-statement blocks instead — it disables autocommit for just that block).
|
||||||
"""
|
"""
|
||||||
|
if pool_kwargs.get("autocommit") is False:
|
||||||
|
raise ValueError(
|
||||||
|
"mysql: autocommit=False is not supported via pool_kwargs — layer-1 verbs and "
|
||||||
|
"raw execute() need autocommit to persist their writes; use db.transaction() "
|
||||||
|
"for an atomic multi-statement block instead"
|
||||||
|
)
|
||||||
self._config = dict(
|
self._config = dict(
|
||||||
host=host,
|
host=host,
|
||||||
port=port,
|
port=port,
|
||||||
@@ -409,9 +417,18 @@ class _Transaction:
|
|||||||
def _where(conditions: Optional[Dict[str, Any]]) -> tuple:
|
def _where(conditions: Optional[Dict[str, Any]]) -> tuple:
|
||||||
"""build a parameterized `WHERE col = %s AND ...` clause + the params list
|
"""build a parameterized `WHERE col = %s AND ...` clause + the params list
|
||||||
|
|
||||||
returns ("", []) when there are no conditions. equality only.
|
returns ("", []) when there are no conditions. equality only. a None value renders as
|
||||||
|
`col IS NULL` (not `col = %s` bound to NULL, which sql never matches) and does not
|
||||||
|
consume a placeholder.
|
||||||
"""
|
"""
|
||||||
if not conditions:
|
if not conditions:
|
||||||
return "", []
|
return "", []
|
||||||
clause = " AND ".join(f"{_quote_ident(c)} = %s" for c in conditions)
|
parts = []
|
||||||
return f" WHERE {clause}", list(conditions.values())
|
params = []
|
||||||
|
for col, val in conditions.items():
|
||||||
|
if val is None:
|
||||||
|
parts.append(f"{_quote_ident(col)} IS NULL")
|
||||||
|
else:
|
||||||
|
params.append(val)
|
||||||
|
parts.append(f"{_quote_ident(col)} = %s")
|
||||||
|
return f" WHERE {' AND '.join(parts)}", params
|
||||||
|
|||||||
Reference in New Issue
Block a user