Skip to content

Commit f5232cb

Browse files
committed
set autocommit to None
None passing to aiomysql means it'll respect the server setup for autocommit.
1 parent 635d92e commit f5232cb

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

mysql_tests/conftest.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ def sa_engine():
2323
@pytest.fixture
2424
@async_generator
2525
async def engine(sa_engine):
26-
e = await gino.create_engine(MYSQL_URL, echo=ECHO, minsize=10,
27-
autocommit=True)
26+
e = await gino.create_engine(MYSQL_URL, echo=ECHO, minsize=10)
2827
await yield_(e)
2928
await e.close()
3029
sa_engine.execute("DELETE FROM gino_user_settings")
@@ -35,9 +34,7 @@ async def engine(sa_engine):
3534
@pytest.fixture
3635
@async_generator
3736
async def bind(sa_engine):
38-
async with db.with_bind(
39-
MYSQL_URL, echo=ECHO, minsize=10, autocommit=True,
40-
) as e:
37+
async with db.with_bind(MYSQL_URL, echo=ECHO, minsize=10) as e:
4138
await yield_(e)
4239
sa_engine.execute("DELETE FROM gino_user_settings")
4340
sa_engine.execute("DELETE FROM gino_users")

mysql_tests/test_bakery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class BakeOnClass(db.Model):
152152
def getter(cls):
153153
return cls.query.where(cls.name == db.bindparam("name"))
154154

155-
async with db.with_bind(MYSQL_URL, prebake=False, autocommit=True):
155+
async with db.with_bind(MYSQL_URL, prebake=False):
156156
await db.gino.create_all()
157157
try:
158158
await BakeOnClass.create(name="exist")

mysql_tests/test_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def test_engine_only():
2929
Column("email_address", String(255), nullable=False),
3030
)
3131

32-
engine = await gino.create_engine(MYSQL_URL, autocommit=True)
32+
engine = await gino.create_engine(MYSQL_URL)
3333
await GinoSchemaVisitor(metadata).create_all(engine)
3434
try:
3535
ins = users.insert().values(name="jack", fullname="Jack Jones")
@@ -62,7 +62,7 @@ async def test_core():
6262
db.Column("email_address", db.String(255), nullable=False),
6363
)
6464

65-
async with db.with_bind(MYSQL_URL, autocommit=True):
65+
async with db.with_bind(MYSQL_URL):
6666
await db.gino.create_all()
6767
try:
6868
await users.insert().values(
@@ -93,7 +93,7 @@ class Address(db.Model):
9393
user_id = db.Column(None, db.ForeignKey("users.id"))
9494
email_address = db.Column(db.String(255), nullable=False)
9595

96-
async with db.with_bind(MYSQL_URL, autocommit=True):
96+
async with db.with_bind(MYSQL_URL):
9797
await db.gino.create_all()
9898
try:
9999
await User.create(name="jack", fullname="Jack Jones")

mysql_tests/test_crud.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async def test_multiple_primary_key_order():
122122
import gino
123123

124124
db1 = gino.Gino()
125-
await db1.set_bind(MYSQL_URL, autocommit=True)
125+
await db1.set_bind(MYSQL_URL)
126126

127127
class NameCard(db1.Model):
128128
__tablename__ = "name_cards"
@@ -152,7 +152,7 @@ class NameCard(db1.Model):
152152
await db1.pop_bind().close()
153153

154154
db2 = gino.Gino(MYSQL_URL)
155-
await db2.set_bind(MYSQL_URL, autocommit=True)
155+
await db2.set_bind(MYSQL_URL)
156156

157157
class NameCard(db2.Model):
158158
__tablename__ = "name_cards"

src/gino/dialects/aiomysql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ async def _init(self):
228228
db=self._url.database,
229229
password=self._url.password,
230230
)
231+
# aiomysql sets autocommit as False by default, which opposes the MySQL
232+
# default, therefore it's set to None to respect the MySQL configuration
233+
args.setdefault("autocommit", None)
231234
self._pool = await aiomysql.create_pool(**args)
232235
return self
233236

0 commit comments

Comments
 (0)