Migrating from oursql to pymysql: different transaction handling??

71 views
Skip to first unread message

Liav Koren

unread,
Jan 8, 2021, 1:59:42 PM1/8/21
to PyMySQL Users

Hi. I'm migrating a python2 code base that used oursql to pymysql. I've noticed that pymysql doesn't automatically commit writes and have updated our application code to called connection.commit() after a successful write.

One thing that I'm confused about and currently digging into is that read isolation appears to be different. I have an application method that causes an update to be written to a row and committed on success, simplified version is:

def cancel_event(event_id):
    event_object = event.get(event_id)
    try:
        event.update(event_id, cancel_payload)  # committed write occurs here, using cursor.transaction.commit
        event_object = event.get(event_id)
        return jsonify(event_object)
    except NotFound as e:
        return jsonify(success=False, message=str(e)), 400



Using oursql the refresh `event_object = event.get(event_id)` sees the updated row just by doing a `cursor.execute('select * events where id = event_id')`. However using pymysql, the committed row is only visible to this process if I do

cursor.connection.begin()
cursor.execute('select * events where id = event_id')

DB config hasn't changed. I'm surprised that the read requires a new transaction to be started in order to see the committed update, and I'm uncertain if this will have larger implications for the rest of the application.

L

Inada Naoki

unread,
Jan 9, 2021, 12:42:44 AM1/9/21
to PyMySQL Users
I never used oursql, and I don't understand what `event.update` and `event.get()` do actually.
Please write a complete and reproducible example which use PyMySQL directly.
Reply all
Reply to author
Forward
0 new messages