From: Mike Bayer Date: Mon, 23 Aug 2010 22:17:31 +0000 (-0400) Subject: - the history_meta versioning recipe sets "unique=False" X-Git-Tag: rel_0_6_4~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=42eb68664445c217681479b50fc8b32ff6ca1749;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - the history_meta versioning recipe sets "unique=False" when copying columns, so that the versioning table handles multiple rows with repeating values. [ticket:1887] --- diff --git a/CHANGES b/CHANGES index e099f68ae0..6e41063a50 100644 --- a/CHANGES +++ b/CHANGES @@ -207,6 +207,11 @@ CHANGES custom cache code is portable and now within "caching_query.py". This allows the example to be easier to "drop in" to existing projects. + + - the history_meta versioning recipe sets "unique=False" + when copying columns, so that the versioning + table handles multiple rows with repeating values. + [ticket:1887] 0.6.3 ===== diff --git a/examples/versioning/history_meta.py b/examples/versioning/history_meta.py index a7b03c5bfc..c2b283f1a0 100644 --- a/examples/versioning/history_meta.py +++ b/examples/versioning/history_meta.py @@ -31,6 +31,7 @@ def _history_mapper(local_mapper): continue col = column.copy() + col.unique = False if super_mapper and col_references_table(column, super_mapper.local_table): super_fks.append((col.key, list(super_history_mapper.base_mapper.local_table.primary_key)[0])) @@ -160,5 +161,4 @@ class VersionedListener(SessionExtension): for obj in versioned_objects(session.dirty): create_version(obj, session) for obj in versioned_objects(session.deleted): - create_version(obj, session, deleted = True) - + create_version(obj, session, deleted = True) \ No newline at end of file diff --git a/examples/versioning/test_versioning.py b/examples/versioning/test_versioning.py index 1a72a06592..2a7a2ca668 100644 --- a/examples/versioning/test_versioning.py +++ b/examples/versioning/test_versioning.py @@ -244,5 +244,28 @@ class TestVersioning(TestBase): SubClassHistory(id=2, name=u's1', type=u'sub', version=1) ] ) + + def test_unique(self): + class SomeClass(Base, ComparableEntity): + __tablename__ = 'sometable' + + id = Column(Integer, primary_key=True) + name = Column(String(50), unique=True) + data = Column(String(50)) + + self.create_tables() + sess = Session() + sc = SomeClass(name='sc1', data='sc1') + sess.add(sc) + sess.commit() + + sc.data = 'sc1modified' + sess.commit() + + assert sc.version == 2 + + sc.data = 'sc1modified2' + sess.commit() + assert sc.version == 3