Commits

Mike Bayer committed 5d76044

allow SQLA-defaults on table columns that are excluded in the mapper

  • Participants
  • Parent commits af8c8b0

Comments (0)

Files changed (2)

File lib/sqlalchemy/orm/mapper.py

             generated_cols.append(self.version_id_col)
 
         for c in generated_cols:
-            if c.key in params:
+            if c.key in params and c in self._columntoproperty:
                 self._set_state_attr_by_column(state, c, params[c.key])
 
         deferred_props = [prop.key for prop in [self._columntoproperty[c] for c in postfetch_cols]]

File test/orm/defaults.py

         eq_(d1.col3, 'up')
         eq_(d1.col4, 'up')
 
-
+class ExcludedDefaultsTest(_base.MappedTest):
+    def define_tables(self, metadata):
+        dt = Table('dt', metadata,
+                   Column('id', Integer, primary_key=True),
+                   Column('col1', String(20), default="hello"),
+        )
+        
+    @testing.resolve_artifact_names
+    def test_exclude(self):
+        class Foo(_base.ComparableEntity):
+            pass
+        mapper(Foo, dt, exclude_properties=('col1',))
+    
+        f1 = Foo()
+        sess = create_session()
+        sess.add(f1)
+        sess.flush()
+        eq_(dt.select().execute().fetchall(), [(1, "hello")])
+    
 if __name__ == "__main__":
     testenv.main()