diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/sql.py | 2 | ||||
-rw-r--r-- | test/sql/labels.py | 9 |
3 files changed, 13 insertions, 1 deletions
@@ -60,6 +60,9 @@ 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 diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 988366617..a7ca55e31 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -2360,7 +2360,7 @@ class _Label(ColumnElement): 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) diff --git a/test/sql/labels.py b/test/sql/labels.py index 53022a6a0..d69a67ef4 100644 --- a/test/sql/labels.py +++ b/test/sql/labels.py @@ -5,6 +5,15 @@ from sqlalchemy import * # 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 |