Opened 4 years ago

Closed 4 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:

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

Change History (1)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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.

Note: See TracTickets for help on using tickets.
Back to Top