Commits

Mike Bayer committed fefad8d

- the label() method on ColumnElement will properly propigate the
TypeEngine of the base element out to the label, including a label()
created from a scalar=True select() statement.

Comments (0)

Files changed (3)

       are to work around glitchy SQLite behavior that doesnt understand
       "foo.id" as equivalent to "id", are now only generated in the case 
       that those named columns are selected from (part of [ticket:513])
+    - the label() method on ColumnElement will properly propigate the
+      TypeEngine of the base element out to the label, including a label()
+      created from a scalar=True select() statement.
     - MS-SQL better detects when a query is a subquery and knows not to
       generate ORDER BY phrases for those [ticket:513]
     - fix for fetchmany() "size" argument being positional in most

lib/sqlalchemy/sql.py

             obj = obj.obj
         self.obj = obj
         self.case_sensitive = getattr(obj, "case_sensitive", True)
-        self.type = sqltypes.to_instance(type)
+        self.type = sqltypes.to_instance(type or getattr(obj, 'type', None))
         obj.parens=True
 
     key = property(lambda s: s.name)

test/sql/labels.py

 # TODO: either create a mock dialect with named paramstyle and a short identifier length,
 # or find a way to just use sqlite dialect and make those changes
 
+class LabelTypeTest(testbase.PersistTest):
+    def test_type(self):
+        m = MetaData()
+        t = Table('sometable', m, 
+            Column('col1', Integer),
+            Column('col2', Float))
+        assert isinstance(t.c.col1.label('hi').type, Integer)
+        assert isinstance(select([t.c.col2], scalar=True).label('lala').type, Float)
+
 class LongLabelsTest(testbase.PersistTest):
     def setUpAll(self):
         global metadata, table1