From: Mike Bayer Date: Wed, 9 Feb 2011 20:14:54 +0000 (-0500) Subject: - Fixed bug where a column with a SQL or server side default X-Git-Tag: rel_0_7b1~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34f26ee255bf64cf6de6fb9a5f1285b696fa4bbd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug where a column with a SQL or server side default that was excluded from a mapping with include_properties or exclude_properties would result in UnmappedColumnError. [ticket:1995] --- diff --git a/CHANGES b/CHANGES index cf0c0eb017..dec011438b 100644 --- a/CHANGES +++ b/CHANGES @@ -218,6 +218,11 @@ CHANGES from that target. Also emits the correct WHERE criterion when using single table inheritance. [ticket:2038] + - Fixed bug where a column with a SQL or server side default + that was excluded from a mapping with include_properties + or exclude_properties would result in UnmappedColumnError. + [ticket:1995] + - sql - Column.copy(), as used in table.tometadata(), copies the 'doc' attribute. [ticket:2028] diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index db445076c8..a6d2c95f51 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1937,7 +1937,8 @@ class Mapper(object): if postfetch_cols: state.expire_attributes(state.dict, [self._columntoproperty[c].key - for c in postfetch_cols] + for c in postfetch_cols if c in + self._columntoproperty] ) # synchronize newly inserted ids from one table to the next diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index 0ee5e44bd6..abef6ed186 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -533,6 +533,21 @@ class MapperTest(_fixtures.FixtureTest): Foo, inherits=Person, polymorphic_identity='foo', exclude_properties=('type', ), ) + @testing.resolve_artifact_names + @testing.provide_metadata + def test_prop_filters_defaults(self): + t = Table('t', metadata, + Column('id', Integer(), primary_key=True, test_needs_autoincrement=True), + Column('x', Integer(), nullable=False, server_default='0') + ) + t.create() + class A(object): + pass + mapper(A, t, include_properties=['id']) + s = Session() + s.add(A()) + s.commit() + @testing.resolve_artifact_names def test_mapping_to_join_raises(self):