From 7217711f46ed41f5d657f5f1b522a73ad2f307a0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 5 Sep 2010 11:28:43 -0400 Subject: - mapper _get_col_to_prop private method used by the versioning example is deprecated; now use mapper.get_property_by_column() which will remain the public method for this. - turned TODO in the history example into an assertion with a descriptive reason --- examples/versioning/history_meta.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/versioning/history_meta.py b/examples/versioning/history_meta.py index c2b283f1a..d2d7c1247 100644 --- a/examples/versioning/history_meta.py +++ b/examples/versioning/history_meta.py @@ -123,7 +123,7 @@ def create_version(obj, session, deleted = False): # mapped column. this will allow usage of MapperProperties # that have a different keyname than that of the mapped column. try: - prop = obj_mapper._get_col_to_prop(obj_col) + prop = obj_mapper.get_property_by_column(obj_col) except UnmappedColumnError: # in the case of single table inheritance, there may be # columns on the mapped table intended for the subclass only. @@ -144,7 +144,9 @@ def create_version(obj, session, deleted = False): elif u: attr[hist_col.key] = u[0] else: - raise Exception("TODO: what makes us arrive here ?") + assert False, "Attribute had no previous state. "\ + "This indicates active_history isn't "\ + "working as expected." if not obj_changed and not deleted: return -- cgit v1.2.1 From bc26030e6f4e5bdb50338b88b3eb4c888eb7bae0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 5 Sep 2010 14:51:00 -0400 Subject: - the versioning example works correctly now if versioning on a col that was formerly NULL. --- examples/versioning/history_meta.py | 6 +++--- examples/versioning/test_versioning.py | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/versioning/history_meta.py b/examples/versioning/history_meta.py index d2d7c1247..0a631e849 100644 --- a/examples/versioning/history_meta.py +++ b/examples/versioning/history_meta.py @@ -144,9 +144,9 @@ def create_version(obj, session, deleted = False): elif u: attr[hist_col.key] = u[0] else: - assert False, "Attribute had no previous state. "\ - "This indicates active_history isn't "\ - "working as expected." + # if the attribute had no value. + attr[hist_col.key] = a[0] + obj_changed = True if not obj_changed and not deleted: return diff --git a/examples/versioning/test_versioning.py b/examples/versioning/test_versioning.py index 2a7a2ca66..031d7ca26 100644 --- a/examples/versioning/test_versioning.py +++ b/examples/versioning/test_versioning.py @@ -86,8 +86,23 @@ class TestVersioning(TestBase): ] ) - - + def test_from_null(self): + class SomeClass(Base, ComparableEntity): + __tablename__ = 'sometable' + + id = Column(Integer, primary_key=True) + name = Column(String(50)) + + self.create_tables() + sess = Session() + sc = SomeClass() + sess.add(sc) + sess.commit() + + sc.name = 'sc1' + sess.commit() + + assert sc.version == 2 def test_deferred(self): """test versioning of unloaded, deferred columns.""" -- cgit v1.2.1