summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-05-18 20:35:01 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-05-27 21:19:06 -0400
commit47552aa93bedcce3756dc89774f02db9f1868e68 (patch)
tree4a00be1f85b5964e8cf6d035ed94345eba0459e4 /lib/sqlalchemy/orm/util.py
parent8b2eb2a2d0f4c7e283d96cf3e5263b5dd48e3b14 (diff)
downloadsqlalchemy-47552aa93bedcce3756dc89774f02db9f1868e68.tar.gz
Use roles for ORM alias() conversion
as SELECT statements will have subquery() and not alias(), start getting ready for the places where the ORM coerces SELECTs into subqueries and be ready to warn about it Change-Id: I90d4b6cae2c72816c6b192016ce074589caf4731
Diffstat (limited to 'lib/sqlalchemy/orm/util.py')
-rw-r--r--lib/sqlalchemy/orm/util.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py
index e57418106..c7e338848 100644
--- a/lib/sqlalchemy/orm/util.py
+++ b/lib/sqlalchemy/orm/util.py
@@ -29,7 +29,9 @@ from .. import exc as sa_exc
from .. import inspection
from .. import sql
from .. import util
+from ..sql import coercions
from ..sql import expression
+from ..sql import roles
from ..sql import util as sql_util
@@ -204,11 +206,10 @@ def polymorphic_union(
for key in table_map:
table = table_map[key]
- # mysql doesn't like selecting from a select;
- # make it an alias of the select
- if isinstance(table, sql.Select):
- table = table.alias()
- table_map[key] = table
+ table = coercions.expect(
+ roles.StrictFromClauseRole, table, allow_select=True
+ )
+ table_map[key] = table
m = {}
for c in table.c:
@@ -466,7 +467,7 @@ class AliasedClass(object):
):
mapper = _class_to_mapper(cls)
if alias is None:
- alias = mapper._with_polymorphic_selectable.alias(
+ alias = mapper._with_polymorphic_selectable._anonymous_fromclause(
name=name, flat=flat
)
@@ -829,7 +830,7 @@ def aliased(element, alias=None, name=None, flat=False, adapt_on_names=False):
raise sa_exc.ArgumentError(
"adapt_on_names only applies to ORM elements"
)
- return element.alias(name, flat=flat)
+ return element._anonymous_fromclause(name=name, flat=flat)
else:
return AliasedClass(
element,
@@ -896,7 +897,7 @@ def with_polymorphic(
.. seealso:: :meth:`.Join.alias`
- :param selectable: a table or select() statement that will
+ :param selectable: a table or subquery that will
be used in place of the generated FROM clause. This argument is
required if any of the desired classes use concrete table
inheritance, since SQLAlchemy currently cannot generate UNIONs
@@ -930,7 +931,7 @@ def with_polymorphic(
classes, selectable, innerjoin=innerjoin
)
if aliased or flat:
- selectable = selectable.alias(flat=flat)
+ selectable = selectable._anonymous_fromclause(flat=flat)
return AliasedClass(
base,
selectable,