]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where a column with a SQL or server side default
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Feb 2011 20:16:13 +0000 (15:16 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Feb 2011 20:16:13 +0000 (15:16 -0500)
that was excluded from a mapping with include_properties
or exclude_properties would result in UnmappedColumnError.
[ticket:1995]

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/test_mapper.py

diff --git a/CHANGES b/CHANGES
index 25c6aa08cd66946133a6b60837592aa0687e382c..8d38759a33902fa1e4a51edd0c2f5d964e85af56 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -21,6 +21,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]
index c4e884efde3cb2ce3e9573f31dd82627dfce16fe..1f5e30f8187fc392b808712fcb01d9003bf8a3ef 100644 (file)
@@ -1953,7 +1953,8 @@ class Mapper(object):
         if postfetch_cols:
             sessionlib._expire_state(state, 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
index 8762e1e2951e40b5373d4eb86b8d26fc05c2037f..d25fb2826b39ac836e2ecf6e0903b471466e7fa0 100644 (file)
@@ -6,8 +6,12 @@ from sqlalchemy.test import testing, pickleable
 from sqlalchemy import MetaData, Integer, String, ForeignKey, func, util
 from sqlalchemy.test.schema import Table, Column
 from sqlalchemy.engine import default
-from sqlalchemy.orm import mapper, relationship, backref, create_session, class_mapper, compile_mappers, reconstructor, validates, aliased
-from sqlalchemy.orm import defer, deferred, synonym, attributes, column_property, composite, relationship, dynamic_loader, comparable_property,AttributeExtension
+from sqlalchemy.orm import mapper, relationship, backref, \
+    create_session, class_mapper, compile_mappers, reconstructor, \
+    validates, aliased
+from sqlalchemy.orm import defer, deferred, synonym, attributes, \
+    column_property, composite, relationship, dynamic_loader, \
+    comparable_property, AttributeExtension, Session
 from sqlalchemy.test.testing import eq_, AssertsCompiledSQL
 from test.orm import _base, _fixtures
 from sqlalchemy.test.assertsql import AllOf, CompiledSQL
@@ -570,6 +574,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):