Opened 13 years ago
Closed 13 years ago
#17771 closed Bug (wontfix)
weird problem db with autocommit
Reported by: | meister | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hello,
Here is problematic code (standard django setup, mysql backend):
import time import os, sys, re sys.path.append(os.path.abspath(os.path.dirname(__file__))+'/..') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from django.conf import settings from django.contrib.auth.models import User #from django.db import connection #cursor = connection.cursor() #cursor.execute('SET autocommit = 1') while True: u = User.objects.get(pk=1) print u.first_name time.sleep(1)
It displays user first_name each second. On the other hand with mysql client :
$ update auth_user set first_name = "foo" where id=1;
Value does not update in my loop (wireshark shows the old value too in the mysql packets dumped). If I restart the process, it fetch the correct new value.
I can fix the problem by adding the 3 autocommit lines commented out.
Problem do not occur on my ubuntu 32b desktop (32bits django 1.3.1 / MySQL-python 1.2.3, mysql 5.1.58) nor a debian squeeze server (32bits mysql 5.1.49).
Problem occurs on a 64 bits debian squeeze server (64bits mysql 5.1.49) and a ubuntu 64 server (64 bits mysql 5.1.41).
Thanks.
Change History (4)
comment:1 by , 13 years ago
follow-up: 3 comment:2 by , 13 years ago
The problem seems to be that you are running in a transaction with repeatable read semantics. I don't think Django supports autocommit for MySQL.
follow-up: 4 comment:3 by , 13 years ago
Replying to akaariai:
The problem seems to be that you are running in a transaction with repeatable read semantics. I don't think Django supports autocommit for MySQL.
It doesn't explain why my code works on some environments and do not work on others...
comment:4 by , 13 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Replying to meister <admin@…>:
Replying to akaariai:
The problem seems to be that you are running in a transaction with repeatable read semantics. I don't think Django supports autocommit for MySQL.
It doesn't explain why my code works on some environments and do not work on others...
It works when using MyISAM and creates some problem with InnoDB. My problem is explained in http://groups.google.com/group/django-users/msg/55fa3724d2754013?pli=1.
A easier way to reproduce it :
aaa