]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed bug in get_history() when referring
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Dec 2011 18:24:11 +0000 (13:24 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Dec 2011 18:24:11 +0000 (13:24 -0500)
to a composite attribute that has no value;
added coverage for get_history() regarding
composites which is otherwise just a userland
function.

CHANGES
lib/sqlalchemy/orm/descriptor_props.py
test/orm/test_composites.py

diff --git a/CHANGES b/CHANGES
index 42318e631cdcb9490b74683c19fd839162d3162c..791547e00188af79b96c459d1c205b0c28522e78 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -118,6 +118,12 @@ CHANGES
     New example in the relationship docs illustrates
     its use.
 
+  - [bug] Fixed bug in get_history() when referring
+    to a composite attribute that has no value;
+    added coverage for get_history() regarding 
+    composites which is otherwise just a userland
+    function.
+
 - sql
    - [bug] related to [ticket:2316], made some 
      adjustments to the change from [ticket:2261]
index c4d59defadabb31648fea53703572eb25e977d0a..6b971376a32a06ca7c8c504cdd44436b78f67440 100644 (file)
@@ -253,7 +253,11 @@ class CompositeProperty(DescriptorProperty):
             if hist.has_changes():
                 has_history = True
 
-            added.extend(hist.non_deleted())
+            non_deleted = hist.non_deleted()
+            if non_deleted:
+                added.extend(non_deleted)
+            else:
+                added.append(None)
             if hist.deleted:
                 deleted.extend(hist.deleted)
             else:
index 60eaf2df1d55d3f4983cc37af578f40840171f4d..b4e3d016cffb9b56bed2ad2278b709ba819f39f4 100644 (file)
@@ -184,6 +184,23 @@ class PointTest(fixtures.MappedTest):
             []
         )
 
+    def test_get_history(self):
+        Edge = self.classes.Edge
+        Point = self.classes.Point
+        from sqlalchemy.orm.attributes import get_history
+
+        e1 = Edge()
+        e1.start = Point(1,2)
+        eq_(
+            get_history(e1, 'start'),
+            ([Point(x=1, y=2)], (), [Point(x=None, y=None)])
+        )
+
+        eq_(
+            get_history(e1, 'end'),
+            ((), [Point(x=None, y=None)], ())
+        )
+
     def test_query_cols(self):
         Edge = self.classes.Edge