On Wed, Feb 21, 2018 at 6:33 AM, Jeff Horemans <[email protected]> wrote:
> When migrating from 1.1 tot 1.2, we noticed that the version_id is not
> getting set on a class that maps to a select of a table.
> I've added a test case class below to the test_versioning.py included in
> SQLAlchemy to confirm this behaviour.
> This case runs fine in versions 1.0 and 1.1, but gives a KeyError on the
> version_id in 1.2 as shown in the stack traces below.
>
> I'll be happy to make an issue on the repository if needed.
no need, this is completely perfect, I'll create the issue. I hope to
get this into 1.2.4 which I need to release hopefully this week /
today preferred (but I've wanted to release for two days already, ran
out of time). thanks!
>
> class VersioningSelectTest(fixtures.MappedTest):
>
> __backend__ = True
>
> @classmethod
> def define_tables(cls, metadata):
> Table('version_table', metadata,
> Column('id', Integer, primary_key=True,
> test_needs_autoincrement=True),
> Column('version_id', Integer, nullable=False),
> Column('value', String(40), nullable=False))
>
> @classmethod
> def setup_classes(cls):
> class Foo(cls.Basic):
> pass
>
> def _fixture(self):
> Foo, version_table = self.classes.Foo, self.tables.version_table
>
> current = version_table.select().where(version_table.c.id >
> 0).alias('current_table')
>
> mapper(Foo, current, version_id_col=version_table.c.version_id)
> s1 = Session()
> return s1
>
> @testing.emits_warning(r".*versioning cannot be verified")
> def test_multiple_updates(self):
> Foo = self.classes.Foo
>
> s1 = self._fixture()
> f1 = Foo(value='f1')
> f2 = Foo(value='f2')
> s1.add_all((f1, f2))
> s1.commit()
>
> f1.value = 'f1rev2'
> f2.value = 'f2rev2'
> s1.commit()
>
> eq_(
> s1.query(Foo.id, Foo.value,
> Foo.version_id).order_by(Foo.id).all(),
> [(f1.id, 'f1rev2', 2), (f2.id, 'f2rev2', 2)]
> )
>
>
>
> FAIL
> test/orm/test_versioning.py::VersioningSelectTest_postgresql+psycopg2_9_5_11::()::test_multiple_updates
>
> ================================================================== FAILURES
> ==================================================================
> ___________________________________
> VersioningSelectTest_postgresql+psycopg2_9_5_11.test_multiple_updates
> ____________________________________
> Traceback (most recent call last):
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/orm/test_versioning.py",
> line 131, in test_multiple_updates
> s1.commit()
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/session.py",
> line 943, in commit
> self.transaction.commit()
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/session.py",
> line 467, in commit
> self._prepare_impl()
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/session.py",
> line 447, in _prepare_impl
> self.session.flush()
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/session.py",
> line 2243, in flush
> self._flush(objects)
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/session.py",
> line 2369, in _flush
> transaction.rollback(_capture_exception=True)
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/util/langhelpers.py",
> line 66, in __exit__
> compat.reraise(exc_type, exc_value, exc_tb)
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/session.py",
> line 2333, in _flush
> flush_context.execute()
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/unitofwork.py",
> line 391, in execute
> rec.execute(self)
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/unitofwork.py",
> line 556, in execute
> uow
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/persistence.py",
> line 193, in save_obj
> update_version_id in states_to_update
> File
> "/home/jeffh/vortex-workspace/v-finance/subrepos/SQLAlchemy-1.2.3/test/../lib/sqlalchemy/orm/persistence.py",
> line 1131, in _finalize_insert_update_commands
> if state_dict[mapper._version_id_prop.key] is None:
> KeyError: u'version_id
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.