[SQLObject] Issue with expiring objects.
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Peter W. <pw-...@te...> - 2004-07-04 17:01:12
|
Hi,
I've been looking to use expiring objects from the cache and have been
running into situations where they don't see to be getting expired
correctly.
I've put together a simple test case that in my understand should work
for each of the 3 versions but fails to re-select from the db unless
extra prints are put in and a reset of the variable.
If any one could run the script below and either confirm that it is
failing and should be working or my understanding is incorrect I'd be
very appreciative.
--
Regards,
Peter Wilkinson.
#!/usr/bin/env python2.3
from SQLObject import *
conn = MySQLConnection(user='USER', db='DB', passwd='PASS')
class Contact(SQLObject):
_table = 'test_contact'
_connection = conn
firstname = StringCol()
lastname = StringCol()
#
# version 1 - doesn't work, only selects from the db twice
#
print "----- 1 -----"
Contact.createTable()
Contact.new(firstname = 'First', lastname = 'Last')
a = Contact(1) # first read
b = Contact(1) # cached
print "a: (First) ", a.firstname
print "b: (First) ", b.firstname
conn.query("update test_contact set firstname = 'Change' where id = 1")
b.expire()
a = Contact(1) # read again
print "a: (Change) ", a.firstname # gets correct value
conn.query("update test_contact set firstname = 'Another' where id = 1")
b.expire()
b = Contact(1) # should read again
print "a: (Another) ", a.firstname # this is not correct
print "b: (Another) ", b.firstname # this is not correct
Contact.dropTable()
#
# version 2. sort of works a is out of whack at the end
#
print "----- 2 -----"
Contact.createTable()
Contact.new(firstname = 'First', lastname = 'Last')
a = Contact(1) # first read
b = Contact(1) # cached
print "a: (First) ", a.firstname
print "b: (First) ", b.firstname
conn.query("update test_contact set firstname = 'Change' where id = 1")
b.expire()
a = Contact(1) # read again
print "a: (Change) ", a.firstname # gets correct value
print "b: (Change) ", b.firstname # FIX - this makes b up-to-date after
the next expire
conn.query("update test_contact set firstname = 'Another' where id = 1")
b.expire()
b = Contact(1) # should read again, making a up-to-date
print "a: (Another) ", a.firstname # this is not correct
print "b: (Another) ", b.firstname # gets correct value
Contact.dropTable()
#
# version 3. works
#
print "----- 3 -----"
Contact.createTable()
Contact.new(firstname = 'First', lastname = 'Last')
a = Contact(1) # first read
b = Contact(1) # cached
print "a: (First) ", a.firstname
print "b: (First) ", b.firstname
conn.query("update test_contact set firstname = 'Change' where id = 1")
b.expire()
a = Contact(1) # read again
print "a: (Change) ", a.firstname # gets correct value
print "b: (Change) ", b.firstname # gets correct value
conn.query("update test_contact set firstname = 'Another' where id = 1")
b.expire()
b = Contact(1) # should read again, making a up-to-date
a = Contact(1) # FIX - this makes a up-to-date
print "a: (Another) ", a.firstname # gets correct value
print "b: (Another) ", b.firstname # gets correct value
Contact.dropTable()
|