{"action":"opened","issue":{"url":"https://api.github.com/repos/PyMySQL/PyMySQL/issues/390","labels_url":"https://api.github.com/repos/PyMySQL/PyMySQL/issues/390/labels{/name}","comments_url":"https://api.github.com/repos/PyMySQL/PyMySQL/issues/390/comments","events_url":"https://api.github.com/repos/PyMySQL/PyMySQL/issues/390/events","html_url":"https://github.com/PyMySQL/PyMySQL/issues/390","id":116732303,"number":390,"title":"Without autocommit SELECT returns old data.","user":{"login":"artfulrobot","id":870343,"avatar_url":"https://avatars.githubusercontent.com/u/870343?v=3","gravatar_id":"","url":"https://api.github.com/users/artfulrobot","html_url":"https://github.com/artfulrobot","followers_url":"https://api.github.com/users/artfulrobot/followers","following_url":"https://api.github.com/users/artfulrobot/following{/other_user}","gists_url":"https://api.github.com/users/artfulrobot/gists{/gist_id}","starred_url":"https://api.github.com/users/artfulrobot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artfulrobot/subscriptions","organizations_url":"https://api.github.com/users/artfulrobot/orgs","repos_url":"https://api.github.com/users/artfulrobot/repos","events_url":"https://api.github.com/users/artfulrobot/events{/privacy}","received_events_url":"https://api.github.com/users/artfulrobot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-13T09:28:45Z","updated_at":"2015-11-13T09:28:45Z","closed_at":null,"body":"This might not be a bug, but as my [question at stackoverflow](http://stackoverflow.com/questions/33569457/pymysql-apparently-returning-cached-values-not-rerunning-query) had not received any answers, it appears I'm not the only one vexed by this, so I'm putting it here in case it is a bug. Apols if it's some weird desired behaviour.\r\n\r\n\r\nSet up a database with one table, one row.\r\n\r\n    mysql> CREATE TABLE state (counter INT(10) UNSIGNED NOT NULL) ENGINE=InnoDB;\r\n    mysql> INSERT INTO state VALUES (1);\r\n\r\nThen run this:\r\n\r\n    #!/usr/bin/env python3\r\n    import pymysql.cursors\r\n    import time\r\n\r\n    conn = pymysql.connect(host='localhost',\r\n         # credentials etc.\r\n         cursorclass=pymysql.cursors.DictCursor)\r\n\r\n    while True:\r\n        with conn.cursor() as cursor:\r\n            cursor.execute(\"SELECT * FROM state limit 1;\")\r\n            vals = cursor.fetchone()\r\n            print (vals)\r\n            time.sleep(1)\r\n\r\nThis prints `1` every second. Now while that's running, fire up a MySQL client and update the state table\r\n\r\n    mysql> UPDATE state SET counter = counter + 1;\r\n\r\n(On Debian/MariaDB 10 at least, this client autocommits, but you can issue a COMMIT from the client if you're unsure. And you can test by exiting the CLI client and starting a new one to inspect the table.)\r\n\r\n**I would now expect the running python script to read `2` but it keeps saying `1`.**\r\n\r\nI have found that by passing `autocommit=True`, or issuing `conn.commit()` after the `cursor.execute` line, it works as expected."}}