summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-09-02 23:46:06 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2020-09-08 17:13:48 -0400
commite8600608669d90c4a6385b312d271aed63eb5854 (patch)
treeef984a01c536b2c81d2283b3ca5d9f4395f41dd0 /lib/sqlalchemy/orm
parent0d56a62f721ee6c91d8a8b6a407b959c9215b3b6 (diff)
downloadsqlalchemy-e8600608669d90c4a6385b312d271aed63eb5854.tar.gz
Update select usage to use the new 1.4 format
This change includes mainly that the bracketed use within select() is moved to positional, and keyword arguments are removed from calls to the select() function. it does not yet fully address other issues such as keyword arguments passed to the table.select(). Additionally, allows False / None to both be considered as "disable" for all of select.correlate(), select.correlate_except(), query.correlate(), which establishes consistency with passing of ``False`` for the legact select(correlate=False) argument. Change-Id: Ie6c6e6abfbd3d75d4c8de504c0cf0159e6999108
Diffstat (limited to 'lib/sqlalchemy/orm')
-rw-r--r--lib/sqlalchemy/orm/query.py4
-rw-r--r--lib/sqlalchemy/orm/util.py20
2 files changed, 10 insertions, 14 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 37ff48964..d941d79d2 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -956,7 +956,7 @@ class Query(
"""
self._auto_correlate = False
- if fromclauses and fromclauses[0] is None:
+ if fromclauses and fromclauses[0] in {None, False}:
self._correlate = ()
else:
self._correlate = set(self._correlate).union(
@@ -2374,7 +2374,7 @@ class Query(
Given a case for :func:`.aliased` such as selecting ``User``
objects from a SELECT statement::
- select_stmt = select([User]).where(User.id == 7)
+ select_stmt = select(User).where(User.id == 7)
user_alias = aliased(User, select_stmt)
q = session.query(user_alias).\
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py
index 271a441f0..f7673e0b7 100644
--- a/lib/sqlalchemy/orm/util.py
+++ b/lib/sqlalchemy/orm/util.py
@@ -245,22 +245,18 @@ def polymorphic_union(
result = []
for type_, table in table_map.items():
if typecolname is not None:
- result.append(
- sql.select(
- [col(name, table) for name in colnames]
- + [
- sql.literal_column(
- sql_util._quote_ddl_expr(type_)
- ).label(typecolname)
- ],
- from_obj=[table],
- )
+ cols = [col(name, table) for name in colnames]
+ cols.append(
+ sql.literal_column(sql_util._quote_ddl_expr(type_)).label(
+ typecolname
+ ),
)
+ result.append(sql.select(*cols).select_from(table))
else:
result.append(
sql.select(
- [col(name, table) for name in colnames], from_obj=[table]
- )
+ *[col(name, table) for name in colnames]
+ ).select_from(table)
)
return sql.union_all(*result).alias(aliasname)