There seems to be a bug in how MK stores objects references.
Look at this code:
store =3D MySQLObjectStore(host=3D'localhost')
foo =3D Foo()
bar =3D Bar()
foo =3D store.fetchObjectsOfClass(Foo)
bar =3D foo.bar() # This row gives the "WARNING"
print "foo:", foo, "bar:", bar
Here's the output:
WARNING: Zero serial number. Obj ref =3D 200000000.
foo: <Middle.Foo.Foo instance at 0x814aae4> bar: None
The problem is that when foo is saved to the SQL database,
bar has no serial number yet, and so foo's reference to
bar gets "zero" in the database (Bar doesn't get a serial
number until it gets saved to the database).
Calling saveChanges() before the attribute is set works,
because after saveChanges() every new object have there
serial numbers. But calling saveChanges() several times is
not an elegant solution; I would rather call saveChanges()
just once and have all data manipulation in one single
database transaction if this is possible.
How can this be solved more elegant?
Why not let the store keep a list of all zero-reference-objects
saved to the database during commitInserts(), that is, when
the new objects get inserted to the database. After that, update=
all the objects in the list to the database, now with the correct=
references, because now we know the serial numbers of all=
Stefan Karlsson (stefan@...) +46 (0)90 77 10 30
Everynet Consulting AB, http://www.everynet.se (0)73 986 84 20