[orm-devel] weird bug?
Charles Brandt
lists at st.imul.us
Thu Apr 1 03:16:08 CEST 2004
I'm encountering some strange behavior with the latest CVS version. I think
the same problem is manifesting itself in a few different areas, but I've
come up with a somewhat concise example of what throws the error for me.
(something with the initializaton of a selected relational column?) Note
that the only difference between the two test scripts is the order of
assignment. I'm going to keep investigating, but if anyone else has a quick
answer I'd love to hear it! :)
-Charles.
I have a MapItem that I'm using as the basis for a persistent dictionary
class. The key is a unique string, and the value is a one2one relation with
another dbclass (StickySession):
class MapItem(dbclass):
tableName = "map_items"
columns = { "id" : autoincrement(),
"dvalue" : one2one(StickySession, columnName="dvalue"),
"dkey" : varchar()
}
class StickySession(dbclass):
tableName = "sticky_sessions"
columns = { "id" : autoincrement(),
"sid" : varchar(),
"remote_address" : varchar(),
"creation_time" : datetime(),
"user_ref" : integer(),
"atime" : datetime()
}
########################CODE1#############################
items = conn.select(MapItem, dkey="sam").fetchall()
if items:
for item in items:
conn.delete(item)
### test new item creation:
item = MapItem(dkey="sam")
conn.insert(item)
print "INSERTED ITEM:"
print item
s_item = conn.select(MapItem, dkey='sam').fetchone()
print "\n\nSELECTED ITEM:"
print s_item
item.dvalue = my_s
item.dvalue = my_s2
s_item.dvalue = my_s
s_item.dvalue = my_s2
########################OUTPUT1#############################
DELETE FROM map_items WHERE id=19
INSERT INTO map_items (dkey) VALUES ('sam')
SELECT LAST_INSERT_ID()
SELECT LAST_INSERT_ID()
INSERTED ITEM:
<MapItem (pyid=4385368 <orm.adapters.mysql.datasource.datasource instance at
0x625a8> oid=1 dvalue=<class orm.relationships.one2oneColumn at 0x24a360>
id=20L dkey='sam')>
SELECT map_items.dvalue, map_items.id, map_items.dkey FROM map_items WHERE
map_items.dkey='sam'
SELECTED ITEM:
<MapItem (pyid=4400592 <orm.adapters.mysql.datasource.datasource instance at
0x625a8> oid=1 dvalue=<class orm.relationships.one2oneColumn at 0x24a360>
id=20L dkey='sam')>
UPDATE map_items SET dvalue=NULL WHERE dvalue=1
UPDATE map_items SET dvalue=1 WHERE id=20
UPDATE map_items SET dvalue=NULL WHERE dvalue=2
UPDATE map_items SET dvalue=2 WHERE id=20
UPDATE map_items SET dvalue=NULL WHERE dvalue=1
UPDATE map_items SET dvalue=1 WHERE id=20
UPDATE map_items SET dvalue=NULL WHERE dvalue=2
UPDATE map_items SET dvalue=2 WHERE id=20
########################CODE2#############################
items = conn.select(MapItem, dkey="sam").fetchall()
if items:
for item in items:
conn.delete(item)
### test new item creation:
item = MapItem(dkey="sam")
conn.insert(item)
print "INSERTED ITEM:"
print item
item.dvalue = my_s
item.dvalue = my_s2
s_item = conn.select(MapItem, dkey='sam').fetchone()
print "\n\nSELECTED ITEM:"
print s_item
s_item.dvalue = my_s
s_item.dvalue = my_s2
########################OUTPUT2#############################
SELECT map_items.dvalue, map_items.id, map_items.dkey FROM map_items WHERE
map_items.dkey='sam'
DELETE FROM map_items WHERE id=20
INSERT INTO map_items (dkey) VALUES ('sam')
SELECT LAST_INSERT_ID()
SELECT LAST_INSERT_ID()
INSERTED ITEM:
<MapItem (pyid=4385368 <orm.adapters.mysql.datasource.datasource instance at
0x625a8> oid=1 dvalue=<class orm.relationships.one2oneColumn at 0x24a360>
id=21L dkey='sam')>
UPDATE map_items SET dvalue=NULL WHERE dvalue=1
UPDATE map_items SET dvalue=1 WHERE id=21
UPDATE map_items SET dvalue=NULL WHERE dvalue=2
UPDATE map_items SET dvalue=2 WHERE id=21
SELECT map_items.dvalue, map_items.id, map_items.dkey FROM map_items WHERE
map_items.dkey='sam'
SELECTED ITEM:
<MapItem (pyid=4400592 <orm.adapters.mysql.datasource.datasource instance at
0x625a8> oid=1 dvalue=<class orm.relationships.one2oneColumn at 0x24a360>
id=21L dkey='sam')>
Traceback (most recent call last):
File "session_test.py", line 67, in ?
s_item.dvalue = my_s
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site
-packages/orm/dbclass.py", line 356, in __setattr__
self._data[name].set(value)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site
-packages/orm/relationships.py", line 305, in set
self.ds().execute(
AttributeError: 'NoneType' object has no attribute 'relation'
More information about the orm-devel
mailing list