Opened 13 years ago
Closed 13 years ago
#16054 closed Bug (invalid)
Unexpected DB Caching Behaviour with MySQL
Reported by: | brendoncrawford | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | django@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This example demonstrates faulty caching behaviour using Django ORM with MySQL...
## iPython Shell 1 > from django.contrib.auth.models import User ## iPython Shell 2 > from django.contrib.auth.models import User ## iPython Shell 1 > a = User() > a.username = 'foo' > a.email = 'foo@localhost.com' > a.save() > print a.id >> 1 ## iPython Shell 2 > print User.objects.get(pk=1).id >> 1 ## MySQL Shell 1 > SELECT id FROM auth_user WHERE id = 1 >> 1 ## iPython Shell 1 > b = User() > b.username = 'bar' > b.email = 'bar@localhost.com' > b.save() > print b.id #2 ## iPython Shell 2 > print User.objects.get(pk=2).id >> Raises User.DoesNotExist ## MySQL Shell 1 > SELECT id FROM auth_user WHERE id = 2 >> 2
Note:
See TracTickets
for help on using tickets.
This is a normal and expected behavior for certain transaction isolation modes. See the MySQL docs on transaction isolation modes for more details, or ask on django-users.