On 8/24/15 10:15 AM, Alex Fraser wrote:
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
great, thank you, these issues are both repaired as of d57e5edbcdf915168c613, the diff for his section is:

diff --git a/examples/versioned_history/history_meta.py b/examples/versioned_history/history_meta.py
index 6d7b137..866f2d4 100644
--- a/examples/versioned_history/history_meta.py
+++ b/examples/versioned_history/history_meta.py
@@ -210,13 +210,13 @@ def create_version(obj, session, deleted=False):
             a, u, d = attributes.get_history(obj, prop.key)

             if d:
-                attr[hist_col.key] = d[0]
+                attr[prop.key] = d[0]
                 obj_changed = True
             elif u:
-                attr[hist_col.key] = u[0]
-            else:
+                attr[prop.key] = u[0]
+            elif a:
                 # if the attribute had no value.
-                attr[hist_col.key] = a[0]
+                attr[prop.key] = a[0]
                 obj_changed = True

     if not obj_changed:


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 sqlalchemy+unsubscr...@googlegroups.com <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to