From 47552aa93bedcce3756dc89774f02db9f1868e68 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 18 May 2019 20:35:01 -0400 Subject: 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 --- lib/sqlalchemy/sql/roles.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/sqlalchemy/sql/roles.py') diff --git a/lib/sqlalchemy/sql/roles.py b/lib/sqlalchemy/sql/roles.py index 2d3aaf903..053bd7146 100644 --- a/lib/sqlalchemy/sql/roles.py +++ b/lib/sqlalchemy/sql/roles.py @@ -100,6 +100,30 @@ class FromClauseRole(ColumnsClauseRole): raise NotImplementedError() +class StrictFromClauseRole(FromClauseRole): + # does not allow text() or select() objects + pass + + +class AnonymizedFromClauseRole(StrictFromClauseRole): + # calls .alias() as a post processor + + def _anonymous_fromclause(self, name=None, flat=False): + """A synonym for ``.alias()`` that is only present on objects of this + role. + + This is an implicit assurance of the target object being part of the + role where anonymous aliasing without any warnings is allowed, + as opposed to other kinds of SELECT objects that may or may not have + an ``.alias()`` method. + + The method is used by the ORM but is currently semi-private to + preserve forwards-compatibility. + + """ + return self.alias(name=name, flat=flat) + + class CoerceTextStatementRole(SQLRole): _role_name = "Executable SQL, text() construct, or string statement" -- cgit v1.2.1