diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-08-24 10:54:09 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-08-24 10:54:09 -0400 |
commit | d57e5edbcdf915168c613cdd6da0bd7bea877fa4 (patch) | |
tree | 883de7c3cd83335e6935f7532a70ac537683eca3 | |
parent | 03e47a8255476d9ed50c5aec73e6c272761d67eb (diff) | |
download | sqlalchemy-d57e5edbcdf915168c613cdd6da0bd7bea877fa4.tar.gz |
- Fixed two issues in the "history_meta" example where history tracking
could encounter empty history, and where a column keyed to an alternate
attribute name would fail to track properly. Fixes courtesy
Alex Fraser.
-rw-r--r-- | doc/build/changelog/changelog_10.rst | 9 | ||||
-rw-r--r-- | examples/versioned_history/history_meta.py | 8 | ||||
-rw-r--r-- | examples/versioned_history/test_versioning.py | 65 |
3 files changed, 78 insertions, 4 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index ad8805299..a9a3486c1 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -19,6 +19,15 @@ :version: 1.0.9 .. change:: + :tags: bug, examples + :versions: 1.1.0b1 + + Fixed two issues in the "history_meta" example where history tracking + could encounter empty history, and where a column keyed to an alternate + attribute name would fail to track properly. Fixes courtesy + Alex Fraser. + + .. change:: :tags: bug, orm :tickets: 3510 :versions: 1.1.0b1 diff --git a/examples/versioned_history/history_meta.py b/examples/versioned_history/history_meta.py index 6d7b137eb..866f2d473 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: diff --git a/examples/versioned_history/test_versioning.py b/examples/versioned_history/test_versioning.py index dde73a5ae..3ea240e11 100644 --- a/examples/versioned_history/test_versioning.py +++ b/examples/versioned_history/test_versioning.py @@ -614,3 +614,68 @@ class TestVersioning(TestCase, AssertsCompiledSQL): sess.commit() assert sc.version == 1 + + def test_create_double_flush(self): + + class SomeClass(Versioned, self.Base, ComparableEntity): + __tablename__ = 'sometable' + + id = Column(Integer, primary_key=True) + name = Column(String(30)) + other = Column(String(30)) + + self.create_tables() + + sc = SomeClass() + self.session.add(sc) + self.session.flush() + sc.name = 'Foo' + self.session.flush() + + assert sc.version == 2 + + def test_mutate_plain_column(self): + class Document(self.Base, Versioned): + __tablename__ = 'document' + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String, nullable=True) + description_ = Column('description', String, nullable=True) + + self.create_tables() + + document = Document() + self.session.add(document) + document.name = 'Foo' + self.session.commit() + document.name = 'Bar' + self.session.commit() + + DocumentHistory = Document.__history_mapper__.class_ + v2 = self.session.query(Document).one() + v1 = self.session.query(DocumentHistory).one() + self.assertEqual(v1.id, v2.id) + self.assertEqual(v2.name, 'Bar') + self.assertEqual(v1.name, 'Foo') + + def test_mutate_named_column(self): + class Document(self.Base, Versioned): + __tablename__ = 'document' + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String, nullable=True) + description_ = Column('description', String, nullable=True) + + self.create_tables() + + document = Document() + self.session.add(document) + document.description_ = 'Foo' + self.session.commit() + document.description_ = 'Bar' + self.session.commit() + + DocumentHistory = Document.__history_mapper__.class_ + v2 = self.session.query(Document).one() + v1 = self.session.query(DocumentHistory).one() + self.assertEqual(v1.id, v2.id) + self.assertEqual(v2.description_, 'Bar') + self.assertEqual(v1.description_, 'Foo') |