diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-09-08 13:00:26 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-09-08 13:00:26 -0400 |
| commit | 68a6701c6d72d6c6ef1ea2b7d615273659e8b735 (patch) | |
| tree | aafd38ed52a00323f74af21b329d84571efcc1d1 /test | |
| parent | 176ac6ab0915f99d378c7d9be67e9c0a73ab1800 (diff) | |
| download | sqlalchemy-68a6701c6d72d6c6ef1ea2b7d615273659e8b735.tar.gz | |
- Fixed bug in :meth:`.Session.bulk_save_objects` where a mapped
column that had some kind of "fetch on update" value and was not
locally present in the given object would cause an AttributeError
within the operation.
fixes #3525
Diffstat (limited to 'test')
| -rw-r--r-- | test/orm/test_bulk.py | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/test/orm/test_bulk.py b/test/orm/test_bulk.py index e2a1464a6..7e1b0523f 100644 --- a/test/orm/test_bulk.py +++ b/test/orm/test_bulk.py @@ -2,7 +2,7 @@ from sqlalchemy import testing from sqlalchemy.testing import eq_ from sqlalchemy.testing.schema import Table, Column from sqlalchemy.testing import fixtures -from sqlalchemy import Integer, String, ForeignKey +from sqlalchemy import Integer, String, ForeignKey, FetchedValue from sqlalchemy.orm import mapper, Session from sqlalchemy.testing.assertsql import CompiledSQL from test.orm import _fixtures @@ -156,6 +156,58 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): ) +class BulkUDPostfetchTest(BulkTest, fixtures.MappedTest): + @classmethod + def define_tables(cls, metadata): + Table( + 'a', metadata, + Column( + 'id', Integer, + primary_key=True, + test_needs_autoincrement=True), + Column('x', Integer), + Column('y', Integer, server_default=FetchedValue(), server_onupdate=FetchedValue())) + + @classmethod + def setup_classes(cls): + class A(cls.Comparable): + pass + + @classmethod + def setup_mappers(cls): + A = cls.classes.A + a = cls.tables.a + + mapper(A, a) + + + def test_insert_w_fetch(self): + A = self.classes.A + + s = Session() + a1 = A(x=1) + s.bulk_save_objects([a1]) + s.commit() + + def test_update_w_fetch(self): + A = self.classes.A + + s = Session() + a1 = A(x=1, y=2) + s.add(a1) + s.commit() + + eq_(a1.id, 1) # force a load + a1.x = 5 + s.expire(a1, ['y']) + assert 'y' not in a1.__dict__ + s.bulk_save_objects([a1]) + s.commit() + + eq_(a1.x, 5) + eq_(a1.y, 2) + + class BulkInheritanceTest(BulkTest, fixtures.MappedTest): @classmethod def define_tables(cls, metadata): |
