[ZODB-Dev] Ape newbie
Shane Hathaway
shane at zope.com
Thu May 22 12:14:22 EDT 2003
Adam Groszer wrote:
> Please help, I'm stuck
>
> I brought together from the tests of Ape the attached script,
> tried to change the MappingGateway to write the data to MySQL.
This is a valiant attempt!
The fixed classifier and fixed persistent mapping are getting in your
way. The fixed classifier gives Ape the ability to load a state for
TESTKEY and TEST2KEY even though you haven't stored anything for those
keys yet. The fixed persistent mapping forces the items of the root
PersistentMapping to use particular OIDs.
Ape carefully avoids storing a new object over an existing object unless
it can detect that the new object was derived from the existing object.
When testStoreAndLoad() tries to write to TestRoot and TestRoot2, it
doesn't notice the root already has objects under those names. The
fixed persistent mapping assigns the OIDs of the new objects to the same
OIDs that the old objects had, but at transaction commit Ape discovers
that even though the old objects and the new objects have the same OIDs,
the new objects were not derived from the old objects and you get a
ConflictError.
I can see two options. You can change testStoreAndLoad() so it modifies
the existing TestRoot and TestRoot2 objects rather than replace them.
This should be easy. Or you can use a non-fixed classifier and
non-fixed persistent mapping. A non-fixed classifier would assign a new
OID for each new object, allowing you to replace objects like you can in
normal ZODB. Unfortunately, there isn't yet a general-purpose
classifier designed for use outside Zope. (See apelib.zope2.classifier.)
One other thing that should help is adding the following line to end of
setUp():
root_mapper.checkConfiguration()
This will detect configuration errors early. It has sure helped me.
Shane
More information about the ZODB-Dev
mailing list