From: Mike Bayer Date: Sun, 29 Apr 2007 21:33:05 +0000 (+0000) Subject: - the label() method on ColumnElement will properly propigate the X-Git-Tag: rel_0_3_7~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d5a0729abff9fe4ac86f49d810564037a68b0e3;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/CHANGES b/CHANGES index ea7e68d6c6..2932a76a4c 100644 --- a/CHANGES +++ b/CHANGES @@ -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 988366617f..a7ca55e315 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 53022a6a02..d69a67ef4f 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