Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocommit not ensured after changing user #1069

Closed
everpcpc opened this issue Jun 23, 2017 · 1 comment
Closed

autocommit not ensured after changing user #1069

everpcpc opened this issue Jun 23, 2017 · 1 comment

Comments

@everpcpc
Copy link
Contributor

everpcpc commented Jun 23, 2017

test schema:

root@localhost [test] mysql> show create table test\G
*************************** 1. row ***************************
       Table: test
Create Table: CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8

test script:

import MySQLdb


r = {
    'host': 'localhost',
    'port': 3306,
    'user': 'test1',
    'passwd': 'test1',
    'db': 'test'
}
conn = MySQLdb.connect(**r)
cursor = conn.cursor()

cursor.execute('insert into test values()')
conn.rollback()

r = {
    'host': 'localhost',
    'port': 3306,
    'user': 'test2',
    'passwd': 'test2',
    'db': 'test'
}
conn = MySQLdb.connect(**r)
cursor = conn.cursor()

cursor.execute('insert into test values()')
conn.rollback()
cursor.execute('select @@autocommit')
print(cursor.fetchall())

The latter insert statement will be committed directly instead of rolling back.

The reason is, after changing user, the autocommit on the backend will be set to default true, while last_set_autocommit is still 0 which was set during the former insert query.
So in MySQL_Connection::IsAutoCommit, it is treated as mysql issue 66884 by mistake, and assumes autocommit is false, thus not changing it on the backend.
cc @MOON-CLJ

@renecannao
Copy link
Contributor

Hi @everpcpc . Thank you for the report!
Fixed in 1.4.1 and 1.3.8 .

Before the fix, with insert committed:

$ python bug1069.py
((1L,),)

After the fix, with insert rolled back:

$ python bug1069.py
((0L,),)

renecannao added a commit that referenced this issue Jun 27, 2017
MySQL_Connection::reset() was missing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants