[okfn-help] vdm: strange behavior

Martijn Faassen faassen at startifact.com
Thu Aug 19 20:32:11 BST 2010


Hi there,

I got vdm working with MySQL but I'm getting some strange behavior.

The sequence is quite simple; I create a (ORM mapped) object in rev1,
which has an attribute foo, add it to the session, and commit the
session. Now I create a new revision rev2, modify the foo attribute,
commit the session again.

Now I say, obj.get_as_of(rev1) and inspect the value of the attribute.
I expect it to be the original value. But once every while, it'll
still be the new value! That's quite worrying. :)

Trying to debug the issue, in the test code I saw references to the
following call:

vdm.sqlalchemy.SQLAlchemySession.set_revision(Session, rev1)

instead of what I did before:

session.revision = rev1

What's the difference? What should users be doing?

I might do things wrong in my code, or I might have uncovered a bug
(perhaps because of the use of MySQL)?

Here's a snippet of the test:

  >>> from ...my own code.. import model
  >>> import vdm.sqlalchemy
  >>> rev1 = model.Revision(author=u'me')
  >>> session.add(rev1)
  >>> session.flush()
  >>> vdm.sqlalchemy.SQLAlchemySession.set_revision(Session, rev1) #
or session.revision = rev1

  >>> foo = model.Foo(u'original')
  >>> session.add(foo)
  >>> session.flush()

  >>> foo_id = foo.id

  >>> session.commit()

  >>> session = Session()
  >>> rev2 = model.Revision(author=u'me')
  >>> session.add(rev2)
  >>> session.flush()
  >>> vdm.sqlalchemy.SQLAlchemySession.set_revision(Session, rev2) #
or session.revision = rev2
  >>> fool.text = u"changed the original"

  >>> foo.text
  u'changed the original'

  >>> session.commit()

  >>> old_fool = foo.get_as_of(rev1)
  >>> old_foo.text
  u'original'

The last test fails sometimes, and instead of u'original' I get the
changed version. Re-creating a session (as above) doesn't appear to
help. Refetching foo from the database in the new session doesn't
appear to help either (not in the example). It just fails randomly
once every 10 or so times I run this. Perhaps this is a timing issue
somehow? Has anyone seen this before?

If needed, I can try to whittle my test code down to the most minimal
example including the table and model setup, and post it to the list;
let me know.

Regards,

Martijn



More information about the okfn-help mailing list