Commits

Mike Bayer committed 31dc0d8

- 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]

Comments (0)

Files changed (3)

     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]

lib/sqlalchemy/orm/mapper.py

         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

test/orm/test_mapper.py

             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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.