From: Mike Bayer Date: Wed, 7 Dec 2011 18:24:11 +0000 (-0500) Subject: - [bug] Fixed bug in get_history() when referring X-Git-Tag: rel_0_7_4~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f79c9a221fca87d405b81453888d63e85c201452;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [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. --- diff --git a/CHANGES b/CHANGES index 42318e631c..791547e001 100644 --- 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] diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index c4d59defad..6b971376a3 100644 --- a/lib/sqlalchemy/orm/descriptor_props.py +++ b/lib/sqlalchemy/orm/descriptor_props.py @@ -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: diff --git a/test/orm/test_composites.py b/test/orm/test_composites.py index 60eaf2df1d..b4e3d016cf 100644 --- a/test/orm/test_composites.py +++ b/test/orm/test_composites.py @@ -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