Commits

Michael Trier committed a9bbb8e

Fixed adding of deferred or othe column properties to a declarative class.

Comments (0)

Files changed (3)

     - Corrected the float type so that it correctly maps to a
       SLFloat type when being reflected. [ticket:1273]
 
+- extensions
+
+    - Fixed adding of deferred or other column properties to a
+      declarative class. [ticket:1379]
+
 0.5.3
 =====
 - orm

lib/sqlalchemy/ext/declarative.py

                 _undefer_column_name(key, value)
                 cls.__table__.append_column(value)
                 cls.__mapper__.add_property(key, value)
+            elif isinstance(value, ColumnProperty):
+                for col in value.columns:
+                    if isinstance(col, Column) and col.table is None:
+                        _undefer_column_name(key, col)
+                        cls.__table__.append_column(col)
+                cls.__mapper__.add_property(key, value)
             elif isinstance(value, MapperProperty):
                 cls.__mapper__.add_property(key, _deferred_relation(cls, value))
             else:

test/ext/declarative.py

 from sqlalchemy import exc
 from testlib import sa, testing
 from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, ForeignKeyConstraint, asc, Index
-from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers, backref, clear_mappers, polymorphic_union
+from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers, backref, clear_mappers, polymorphic_union, deferred
 from testlib.testing import eq_
 from orm._base import ComparableEntity, MappedTest
 
             Engineer(name="vlad", primary_language="cobol") 
         )
 
+    def test_add_deferred(self):
+        class Person(Base, ComparableEntity):
+            __tablename__ = 'people'
+            id = Column('id', Integer, primary_key=True)
+
+        Person.name = deferred(Column(String(10)))
+
+        Base.metadata.create_all()
+        sess = create_session()
+        p = Person(name='ratbert')
+
+        sess.add(p)
+        sess.flush()
+        sess.expunge_all()
+        eq_(
+            sess.query(Person).all(),
+            [
+                Person(name='ratbert')
+            ]
+        )
+        person = sess.query(Person).filter(Person.name == 'ratbert').one()
+        assert 'name' not in person.__dict__
+
     def test_single_fksonsub(self):
         """test single inheritance with a foreign key-holding column on a subclass.