Hi Michael,
On Monday, 24 August 2015 12:31:20 UTC+10, Michael Bayer wrote:
>
> yes and no. Yes, if there's no "added" history, that should be skipped as
> you're doing, but no in that that particular line of code is not called if
> an object is being saved for the first time, only on an update, and then
> only if that attribute actually had a change, which you are saying this
> attribute did not.
>
> so if you can please share: 1. a mapping and an exact usage that
> illustrates how this is happening 2. what exact version of SQLAlchemy are
> you using and 3. have you modified the history_meta.py recipe in any way?
>
Oops, sorry for leaving that out the first time. I'm using SQLAlchemy 1.0.8
on Python 3. I have modified *history_meta.py* for my app, but if I revert
the changes the problem is still there.
It turns out that the problem happens when the session gets flushed twice.
For example:
document = Document()
self.session.add(document)
self.session.flush()
document.name = 'Foo'
self.session.flush()
# IndexError: tuple index out of range
In my app I think I need to call flush several times, because I'm building
a tree and I need to know the parent IDs. Perhaps I could rearrange my code
to not need to do this.
Additionally, if I set a different name for a column than the attribute
name (as shown below), the value doesn't get propagated to the history
table.
description_ = Column('description', String, nullable=True)
See here for unit tests for both of these issues. It uses an unmodified
*history_meta.py*.
https://github.com/z0u/satest/blob/master/test_versioned.py
Cheers,
Alex
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.