Commits

Mike Bayer committed 1a8103a

- fix remaining ORM tests

Comments (0)

Files changed (6)

lib/sqlalchemy/orm/query.py

         # .with_only_columns() after we have a core select() so that
         # we get just "SELECT 1" without any entities.
         return sql.exists(self.add_columns('1').with_labels().
-                          statement.with_only_columns(['1']))
+                          statement.with_only_columns([1]))
 
     def count(self):
         """Return a count of rows this Query would return.

test/orm/test_assorted_eager.py

 
 import sqlalchemy as sa
 from sqlalchemy import testing
-from sqlalchemy import Integer, String, ForeignKey
+from sqlalchemy import Integer, String, ForeignKey, table, text
 from sqlalchemy.testing.schema import Table, Column
 from sqlalchemy.orm import mapper, relationship, backref, create_session
 from sqlalchemy.testing import eq_
         q = s.query(Thing).options(sa.orm.joinedload('category'))
         l = (q.filter(
             (tests.c.owner_id==1) &
-            ('options.someoption is null or options.someoption=%s' % false)).
+            text('options.someoption is null or options.someoption=%s' % false)).
              join('owner_option'))
 
         result = ["%d %s" % ( t.id,t.category.name ) for t in l]

test/orm/test_eager_relations.py

     joinedload_all, backref, Session,\
     defaultload, Load
 from sqlalchemy import Integer, String, Date, ForeignKey, and_, select, \
-    func
+    func, text
 from sqlalchemy.testing.schema import Table, Column
 from sqlalchemy.orm import mapper, relationship, create_session, \
     lazyload, aliased, column_property
 
         q = create_session().query(User)
 
-        l = q.filter("users.id in (7, 8, 9)").order_by("users.id")
+        l = q.filter("users.id in (7, 8, 9)").order_by(text("users.id"))
 
         def go():
             eq_(self.static.user_order_result[0:3], l.all())

test/orm/test_froms.py

     fixtures, eq_, assert_raises, assert_raises_message, AssertsCompiledSQL)
 from sqlalchemy import (
     exc as sa_exc, util, Integer, Table, String, ForeignKey, select, func,
-    and_, asc, desc, inspect, literal_column, cast, exists)
+    and_, asc, desc, inspect, literal_column, cast, exists, text)
 from sqlalchemy.orm import (
     configure_mappers, Session, mapper, create_session, relationship,
     column_property, joinedload_all, contains_eager, contains_alias,
         self.assert_compile(
             q3.order_by(c1),
             "SELECT anon_1.c1 AS anon_1_c1, anon_1.c2 "
-            "AS anon_1_c2 FROM (SELECT c1 AS c1, c2 AS c2 WHERE "
-            "c1 = :c1_1 UNION SELECT c1 AS c1, c2 AS c2 "
+            "AS anon_1_c2 FROM (SELECT c1, c2 WHERE "
+            "c1 = :c1_1 UNION SELECT c1, c2 "
             "WHERE c1 = :c1_2) AS anon_1 ORDER BY anon_1.c1"
         )
 
             "SELECT anon_1.anon_2_c1 AS anon_1_anon_2_c1, anon_1.anon_2_c2 AS "
             "anon_1_anon_2_c2 FROM (SELECT anon_2.c1 AS anon_2_c1, anon_2.c2 "
             "AS anon_2_c2 "
-            "FROM (SELECT c1 AS c1, c2 AS c2 WHERE c1 = :c1_1) AS "
+            "FROM (SELECT c1, c2 WHERE c1 = :c1_1) AS "
             "anon_2) AS anon_1 ORDER BY anon_1.anon_2_c1"
         )
 
         self.assert_compile(
             q3.order_by(c1),
             "SELECT anon_1.c1 AS anon_1_c1, anon_1.c2 "
-            "AS anon_1_c2 FROM (SELECT c1 AS c1, c2 AS c2 WHERE "
-            "c1 = :c1_1 UNION SELECT c1 AS c1, c2 AS c2 "
+            "AS anon_1_c2 FROM (SELECT c1, c2 WHERE "
+            "c1 = :c1_1 UNION SELECT c1, c2 "
             "WHERE c1 = :c1_2) AS anon_1 ORDER BY anon_1.c1"
         )
 
         query = users.select(users.c.id == 7).\
             union(users.select(users.c.id > 7)).alias('ulist').\
             outerjoin(addresses).\
-            select(use_labels=True, order_by=['ulist.id', addresses.c.id])
+            select(
+                use_labels=True,
+                order_by=[text('ulist.id'), addresses.c.id])
         sess = create_session()
         q = sess.query(User)
 
         query = users.select(users.c.id == 7).\
             union(users.select(users.c.id > 7)).alias('ulist').\
             outerjoin(addresses). \
-            select(use_labels=True, order_by=['ulist.id', addresses.c.id])
+            select(
+                use_labels=True,
+                order_by=[text('ulist.id'), addresses.c.id])
         sess = create_session()
         q = sess.query(User)
 
         query = users.select(users.c.id == 7).\
             union(users.select(users.c.id > 7)).alias('ulist').\
             outerjoin(addresses). \
-            select(use_labels=True, order_by=['ulist.id', addresses.c.id])
+            select(
+                use_labels=True,
+                order_by=[text('ulist.id'), addresses.c.id])
         sess = create_session()
 
         # better way.  use select_entity_from()
         query = users.select(users.c.id == 7).\
             union(users.select(users.c.id > 7)).\
             alias('ulist').outerjoin(adalias).\
-            select(use_labels=True, order_by=['ulist.id', adalias.c.id])
+            select(use_labels=True, order_by=[text('ulist.id'), adalias.c.id])
 
         def go():
             l = sess.query(User).select_entity_from(query).\

test/orm/test_query.py

     testing, null, exists, text, union, literal, literal_column, func, between,
     Unicode, desc, and_, bindparam, select, distinct, or_, collate, insert,
     Integer, String, Boolean, exc as sa_exc, util, cast)
-from sqlalchemy.sql import operators, column, expression
+from sqlalchemy.sql import operators, expression
+from sqlalchemy import column, table
 from sqlalchemy.engine import default
 from sqlalchemy.orm import (
     attributes, mapper, relationship, create_session, synonym, Session,
         )
 
         for q in (
-                q3.order_by(User.id, "anon_1_param_1"),
+                q3.order_by(User.id, text("anon_1_param_1")),
                 q6.order_by(User.id, "foo")):
             eq_(
                 q.all(),
         User = self.classes.User
 
         s = create_session()
-        assert_raises(sa_exc.InvalidRequestError, s.query,
-                    User.id, text("users.name"))
+        assert_raises(
+            sa_exc.InvalidRequestError, s.query,
+            User.id, text("users.name"))
 
         eq_(
             s.query(User.id, "name").order_by(User.id).all(),
         s = create_session()
         eq_(
             s.query(User).from_statement(
-                select(['id', 'name']).select_from('users').order_by('id'),
+                select([column('id'), column('name')]).
+                select_from(table('users')).order_by('id'),
             ).all(),
             [User(id=7), User(id=8), User(id=9), User(id=10)]
         )
         c = column('x', Boolean)
         self.assert_compile(
             s.query(c).filter(c),
-            "SELECT x AS x WHERE x",
+            "SELECT x WHERE x",
             dialect=self._dialect(True)
         )
 
         c = column('x', Boolean)
         self.assert_compile(
             s.query(c).filter(c),
-            "SELECT x AS x WHERE x = 1",
+            "SELECT x WHERE x = 1",
             dialect=self._dialect(False)
         )
 
         c = column('x', Boolean)
         self.assert_compile(
             s.query(c).filter(~c),
-            "SELECT x AS x WHERE x = 0",
+            "SELECT x WHERE x = 0",
             dialect=self._dialect(False)
         )
 
         c = column('x', Boolean)
         self.assert_compile(
             s.query(c).filter(~c),
-            "SELECT x AS x WHERE NOT x",
+            "SELECT x WHERE NOT x",
             dialect=self._dialect(True)
         )
 
         c = column('x', Boolean)
         self.assert_compile(
             s.query(c).having(c),
-            "SELECT x AS x HAVING x = 1",
+            "SELECT x HAVING x = 1",
             dialect=self._dialect(False)
         )

test/orm/test_selectable.py

 from sqlalchemy.testing import assert_raises, assert_raises_message
 import sqlalchemy as sa
 from sqlalchemy import testing
-from sqlalchemy import String, Integer, select
+from sqlalchemy import String, Integer, select, column
 from sqlalchemy.testing.schema import Table, Column
 from sqlalchemy.orm import mapper, Session
 from sqlalchemy.testing import eq_, AssertsCompiledSQL
         Subset = self.classes.Subset
 
 
-        selectable = select(["x", "y", "z"]).alias()
+        selectable = select([column("x"), column("y"), column("z")]).alias()
         mapper(Subset, selectable, primary_key=[selectable.c.x])
 
         self.assert_compile(
             Session().query(Subset),
-            "SELECT anon_1.x, anon_1.y, anon_1.z FROM (SELECT x, y, z) AS anon_1",
+            "SELECT anon_1.x AS anon_1_x, anon_1.y AS anon_1_y, "
+            "anon_1.z AS anon_1_z FROM (SELECT x, y, z) AS anon_1",
             use_default_dialect=True
         )
 
         Subset = self.classes.Subset
 
 
-        selectable = select(["x", "y", "z"]).alias()
+        selectable = select([column("x"), column("y"), column("z")]).alias()
         assert_raises_message(
             sa.exc.ArgumentError,
             "could not assemble any primary key columns",